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

Unacknowledged writes fail silently when retryWrites=true

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

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

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

              Created:
              Updated:
              Resolved: