[CSHARP-2960] Unacknowledged writes fail silently when retryWrites=true Created: 10/Feb/20  Updated: 28/Oct/23  Resolved: 12/Feb/20

Status: Closed
Project: C# Driver
Component/s: Write Operations
Affects Version/s: 2.10.0
Fix Version/s: 2.10.2

Type: Bug Priority: Critical - P2
Reporter: Peter Gordon Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB 4.2


Issue Links:
Depends
Problem/Incident
is caused by CSHARP-2199 Prohibit using unacknowledged writes ... Closed
Related
related to CSHARP-2199 Prohibit using unacknowledged writes ... Closed

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

 Comments   
Comment by Githook User [ 12/Feb/20 ]

Author:

{'name': 'rstam', 'username': 'rstam', 'email': 'robert@robertstam.org'}

Message: CSHARP-2960: Unacknowledged writes fail silently when retryWrites=true.
Branch: v2.10.x
https://github.com/mongodb/mongo-csharp-driver/commit/61000da0d3a6a14e681470a4e8f3aea99e127cd7

Comment by Githook User [ 12/Feb/20 ]

Author:

{'name': 'rstam', 'username': 'rstam', 'email': 'robert@robertstam.org'}

Message: CSHARP-2960: Unacknowledged writes fail silently when retryWrites=true.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/3aa87b2ba43130257089abd42fdd60ba2e65ac98

Comment by Robert Stam [ 10/Feb/20 ]

Thank you for reporting this issue. We have been able to reproduce it.

We have found a bug related to the combination of retryable writes and unacknowledged writes.

We will fix this ASAP and release a patch release quickly.

Until then there is a less than ideal work around involving turning off retryable writes, which can be done in the connection string like this:

 

var client = new MongoClient("mongodb://localhost/?retryWrites=false");

This is not ideal because it results in retryable writes being disabled, and retryable writes are useful in their own right.

Generated at Wed Feb 07 21:43:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.