[CSHARP-2129] Insert with RetryWrites=true should work on standalone Created: 18/Dec/17  Updated: 28/Oct/23  Resolved: 26/Dec/17

Status: Closed
Project: C# Driver
Component/s: Configuration, Write Operations
Affects Version/s: 2.5
Fix Version/s: 2.5.1

Type: Bug Priority: Major - P3
Reporter: Steffen Schaffert Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows Server 2012 R2 64-bit, MongoDB 3.6, .NET 4.5


Issue Links:
Duplicate
is duplicated by CSHARP-2251 Single insert succeed, but bulk inser... Closed

 Description   

I just updated our development MongoDB instance to MongoDB 3.6 using the C# Driver 2.5. When setting the new option "RetryWrites" in MongoClientSettings to true, I get the error message listed below when trying to insert a new document.

The feature compatibility version is set to 3.6, although this should probably work with older MongoDB versions as well. The database is running on the same server as the code using the C# driver, the database is configured as a standalone instance.

Setting the option "RetryWrites" to false allows the write operation to succeed, so this issue seems to be caused by enabling retries. I would expect this option to work for standalone installations as well as for replica set installations.

Command insert failed: Transaction numbers are only allowed on a replica set member or mongos.
   at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.ProcessReply(ConnectionId connectionId, ReplyMessage`1 reply)
   at MongoDB.Driver.Core.WireProtocol.CommandWireProtocol`1.Execute(IConnection connection, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol`1 protocol, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](ICoreSession session, ReadPreference readPreference, DatabaseNamespace databaseNamespace, BsonDocument command, IElementNameValidator commandValidator, BsonDocument additionalOptions, Func`1 responseHandling, Boolean slaveOk, IBsonSerializer`1 resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.RetryableWriteCommandOperationBase.ExecuteAttempt(RetryableWriteContext context, Int32 attempt, Nullable`1 transactionNumber, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.RetryableWriteOperationExecutor.Execute[TResult](IRetryableWriteOperation`1 operation, RetryableWriteContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.ExecuteBatches(RetryableWriteContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkUnmixedWriteOperationBase`1.Execute(RetryableWriteContext context, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.ExecuteBatch(RetryableWriteContext context, Batch batch, CancellationToken cancellationToken)
   at MongoDB.Driver.Core.Operations.BulkMixedWriteOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken)
   at MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.ExecuteWriteOperation[TResult](IClientSessionHandle session, IWriteOperation`1 operation, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IClientSessionHandle session, IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.<>c__DisplayClass23_0.<BulkWrite>b__0(IClientSessionHandle session)
   at MongoDB.Driver.MongoCollectionImpl`1.UsingImplicitSession[TResult](Func`2 func, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionImpl`1.BulkWrite(IEnumerable`1 requests, BulkWriteOptions options, CancellationToken cancellationToken)
   at MongoDB.Driver.MongoCollectionBase`1.InsertOne(TDocument document, InsertOneOptions options, Action`2 bulkWrite)
   at MongoDB.Driver.MongoCollectionBase`1.InsertOne(TDocument document, InsertOneOptions options, CancellationToken cancellationToken)



 Comments   
Comment by Githook User [ 16/Mar/18 ]

Author:

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

Message: CSHARP-2129: Fix GetClient use of clusterConfigurator.
Branch: v2.5.x
https://github.com/mongodb/mongo-csharp-driver/commit/946f04a8bffc7329584550f06029f3d862ff6e57

Comment by Githook User [ 16/Mar/18 ]

Author:

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

Message: CSHARP-2129: Insert with RetryWrites=true should work on standalone.
Branch: v2.5.x
https://github.com/mongodb/mongo-csharp-driver/commit/c2aa519c261bbc05debc721d55bad257eb5af749

Comment by Githook User [ 26/Dec/17 ]

Author:

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

Message: CSHARP-2129: Fix GetClient use of clusterConfigurator.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/53c1523a9ecaf98ff7df9d6a00e4f55336fd6446

Comment by Githook User [ 26/Dec/17 ]

Author:

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

Message: CSHARP-2129: Insert with RetryWrites=true should work on standalone.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/253d967530ad92abba1bc80afd68900f9abf8bc7

Comment by Robert Stam [ 21/Dec/17 ]

A standalone server does not support retryable writes. Only replica sets and sharded clusters support retryable writes.

However, the driver should know this and should not be sending a transaction number when connected to a standalone server.

A workaround until this is fixed is to not set RetryWrites to true.

Thank you for reporting this.

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