-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: 2.10.0
-
Component/s: Write Operations
-
None
-
Environment:MongoDB 4.2
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); }- is caused by
-
CSHARP-2199 Prohibit using unacknowledged writes with explicit sessions
- Closed
- related to
-
CSHARP-2199 Prohibit using unacknowledged writes with explicit sessions
- Closed