-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.12.1
-
Component/s: Write Operations
-
None
-
Environment:Java 8, MongoDB Atlas M5 4.2.2
There is a very specific combination of factors that must be fulfilled for this to happen:
- Use mongodb-driver-sync 3.12.0 or 3.12.1
- Connect with ?retryWrites=true
- Do a write to a document with WriteConcern.UNACKNOWLEDGED. Driver will log that retryWrites=true cannot be used by unacknowledged.
e.g.
userColl.withWriteConcern(WriteConcern.UNACKNOWLEDGED).updateMany(in("_id", ids), inc("impressionCount", 1));
db.user.updateMany({_id: [466]}, {$inc: {impressionCount: 1, {w: 0});}}
- Do another update with Java for the same document, this time with writeConcern of 1.
db.user.updateOne( {_id: 466}, { $set: { 'email': 'hendy@hendyirawan.com'}}, {w: 1});
- At this point the previous updateOne() is locked and will never return.
- Also, pressing Ctrl+C does not terminate the app. Java app cannot exit. Doing a kill -9 will make connections stuck on the MongoDB server (at least on MongoDB Atlas M10 v4.2.2 it does).
Note that this bug is not reproducible when using mongo shell, so I think this bug is specific to MongoDB Java Driver. At first I thought it is due to codecs or thread safety or server busy, but even just updating a string reproduces the issue.
Workaround:
Don't use WriteConcern.UNACKNOWLEDGED (with ?retryWrites=true). As long as I update always with w=1 or w=majority, there is no issue.
- related to
-
CSHARP-2970 Deadlock using Atlas
- Closed