Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3608

updateOne blocked due to ?retryWriter=true and WriteConcern.UNACKNOWLEDGED combination

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 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:

      1. Use mongodb-driver-sync 3.12.0 or 3.12.1
      2. Connect with ?retryWrites=true
      1. 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});}}

      1. 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});

      1. At this point the previous updateOne() is locked and will never return.
      2. 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.

            Assignee:
            john.stewart@mongodb.com John Stewart (Inactive)
            Reporter:
            hendy@hendyirawan.com Hendy Irawan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: