Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2960

Unacknowledged writes fail silently when retryWrites=true

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 2.10.0
    • Fix Version/s: 2.10.2
    • Component/s: Write Operations
    • Labels:
      None
    • Environment:
      MongoDB 4.2

      Description

      Issue Status as of Feb 12, 2020

      ISSUE DESCRIPTION AND IMPACT

      This issue affects MongoDB C# driver versions 2.10.0 and 2.10.1.

      To be impacted by this bug you must be:

      • Using the MongoDB C# Driver version 2.10.0 or 2.10.1, or another library that has imported either of these driver releases.
      • Using the default driver behavior for retryable writes, which is "retryableWrites=true".
      • Overriding default driver behavior by issuing writes with the Unacknowledged write concern (WriteConcern.Unacknowledged, also known as {w:0}).

      Writes issued in these circumstances incorrectly include a transaction number without a session ID. This causes the server to reject the writes and, because of the specified Unacknowledged write concern, the client is not notified.

      WORKAROUNDS AND REMEDIATION AND FIX VERSIONS

      You can work around this bug in one of two ways:

      • Avoid unacknowledged writes ((WriteConcern.Unacknowledged). Importantly, Unacknowledged is not a recommended WriteConcern setting and should only be used in situations where silently failing writes are acceptable.
      • Disable Retryable Writes by specifying "retryWrites=false" in the connection string provided to the driver. This is a less desirable workaround due to the benefits of retryable writes.

      Unfortunately, it is not possible to identify or determine what writes have been lost unless the application has sufficient logging to provide this information.

      FIX VERSIONS

      A fix for this issue will be included in C# Driver version 2.10.2. All users that use Unacknowledged Writes (WriteConcern.Unacknowledged) are encouraged to upgrade immediately.

      Original Description

      Starting in the c# driver version 2.10.0 with MongoDB 4.2, if we try to insert a document using the WriteConcern Unacknowledged, the document never gets inserted into the collection.  

      Note: the exact code with version 2.9.3 works without issue. 

      Sample code that does not work (no issues on the client but the data never gets to Mongo):

      Public async Task Insert(DataModel model)

      {    IMongoDatabase db = code to get database removed;    var coll = db.GetCollection<DataModel>("CollName");    await coll.WithWriteConcern(WriteConcern.Unacknowledged).InsertOneAsync(model); }

      Sample code that works (can use any write concern but Unacknowledged):

      Public async Task Insert(DataModel model)

      {    IMongoDatabase db = code to get database removed;    var coll = db.GetCollection<DataModel>("CollName");    await coll.WithWriteConcern(WriteConcern.Acknowledged).InsertOneAsync(model); }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              rstam Robert Stam
              Reporter:
              pgordon@truckdown.com Peter Gordon
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: