Retry does not work with BulkWrite operations within the session

The BulkWrite command throws a ClientBulkWriteException when there is a conflict issue. However, this exception does not include the TransientTransactionError label, which is only present in the InnerException.

As a result, the session.WithTransactionAsync method does not automatically retry the operation, as it should.

Steps to Reproduce:

  1. Execute a BulkWrite operation inside a session.WithTransactionAsync block.
  2. Introduce a transient conflict error (e.g., a write conflict).
  3. Observe that the operation fails without retrying, even though retries are expected in this scenario.

Expected Behavior:
The ClientBulkWriteException should include the TransientTransactionError label to ensure session.WithTransactionAsync retries the operation as intended.

Actual Behavior:
The TransientTransactionError label is present only in the InnerException, and the session.WithTransactionAsync method does not retry the operation.

Environment Details:

  • MongoDB Server version: [Your version here]
  • Driver version: [Your driver version here]
  • OS: [Your OS here]

Additional Notes:
This issue disrupts the expected behavior of transaction retries and can lead to manual intervention for handling retries.

Exception example:

"StackTrace" : [ "at MongoDB.Driver.Core.Operations.ClientBulkWriteOperation.EnsureCanProceedNextBatch(ConnectionId connectionId, BulkWriteRawResult bulkWriteResult)", "at MongoDB.Driver.Core.Operations.ClientBulkWriteOperation.ExecuteAsync(IWriteBinding binding, CancellationToken cancellationToken)", "at MongoDB.Driver.OperationExecutor.ExecuteWriteOperationAsync[TResult](IWriteBinding binding, IWriteOperation`1 operation, CancellationToken cancellationToken)", "at MongoDB.Driver.MongoClient.ExecuteWriteOperationAsync[TResult](IClientSessionHandle session, IWriteOperation`1 operation, CancellationToken cancellationToken)",
"[Prop] ErrorLabels" : [ ],
"ExceptionType" : "ClientBulkWriteException",

"InnerExceptions" : [
				{
					"StackTrace" : [
						"at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ProcessResponse(ConnectionId connectionId, CommandMessage responseMessage)",
						"at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.SendMessageAndProcessResponseAsync(CommandRequestMessage message, Int32 responseTo, IConnection connection, CancellationToken cancellationToken)",
						"at MongoDB.Driver.Core.WireProtocol.CommandUsingCommandMessageWireProtocol`1.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)",
						"at MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocolAsync[TResult](IWireProtocol`1 protocol, ICoreSession session, CancellationToken cancellationToken)",
						"at MongoDB.Driver.Core.Operations.RetryableWriteOperationExecutor.ExecuteAsync[TResult](IRetryableWriteOperation`1 operation, RetryableWriteContext context, CancellationToken cancellationToken)",
                    "ExceptionType" : "MongoCommandException",
                    "[Prop] ErrorLabels" : [ "TransientTransactionError" ]

Hi @Fernando_Mondo!

Thank you for reporting the problem. Could you please specify the Driver’s version being used to reproduce the problem? We faced some retriability-related issue with client BulkWrite and it was fixed in 3.1.0. Please make sure you are using the latest version of the Driver.

Thanks,
Oleksandr

Thank you for your response.
Yes, I am using version 3.1.0:

<PackageReference Include="MongoDB.Driver" Version="3.1.0" />

Looking at the driver’s code at mongo-csharp-driver/src/MongoDB.Driver/TransactionExecutor.cs at fc052f42455e8ed6d4c648a178fca272fdb8d181 · mongodb/mongo-csharp-driver · GitHub,

it’s clear that the issue will indeed occur.
The errorLabel is only being checked on the main exception, not on the inner exception.

Thank you for confirming the Driver’s version. I’ve created Jira ticket to fix the issue: https://jira.mongodb.org/browse/CSHARP-5449 . Please refer to the ticket for status updates.

1 Like