-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Describe the bug
Description
Failures while moving delayed messages to the queue are not sufficiently retried, the message ends up on the error queue 7s after the deliver at time where it is reasonable to expect it to be retried inline with the Recoverability configuration.
In this case we are moving from one sql backed endpoint to another (both in the same DB).
28/11/2025 00:05:18.694 Z : We log (user code) that we have publish a delayed message CheckScriptStatusSideEffect with id 24836dbe-915a-4a23-8139-b3a30001756c with a delay of 5s.
In the error queue we see that message and it has been moved to the error queue at 00:05:30 so only 7 seconds after it was set for delivery.
"NServiceBus.MessageId": "24836dbe-915a-4a23-8139-b3a30001756c",
"NServiceBus.TimeSent": "2025-11-28 00:05:18:653833 Z",
"NServiceBus.DeliverAt": "2025-11-28 00:05:23:653833 Z",
"NServiceBus.TimeOfFailure": "2025-11-28 00:05:30:344618 Z",
"NServiceBus.ExceptionInfo.Message": "The service has encountered an error processing your request. Please try again. Error code 9001.\nA severe error occurred on the current command. The results, if any, should be discarded.",
"NServiceBus.ExceptionInfo.Source": "Core Microsoft SqlClient Data Provider",
"NServiceBus.ExceptionInfo.StackTrace": "Microsoft.Data.SqlClient.SqlException (0x80131904): The service has encountered an error processing your request. Please try again. Error code 9001.
A severe error occurred on the current command. The results, if any, should be discarded.
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand command, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
at Microsoft.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction2005(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
at Microsoft.Data.SqlClient.SqlInternalTransaction.Commit()
at Microsoft.Data.SqlClient.SqlTransaction.Commit()
at NServiceBus.Transport.Sql.Shared.ProcessWithNativeTransaction.ProcessMessage(CancellationTokenSource stopBatchCancellationTokenSource, CancellationToken cancellationToken) in /_/src/NServiceBus.Transport.Sql.Shared/Receiving/ProcessWithNativeTransaction.cs:line 53
ClientConnectionId:3404bce4-53f8-42cd-a55c-443314d9c343
Error Number:40197,State:4,Class:20\nClientConnectionId before routing:0c3dd88d-6725-427e-b90e-b08d64748a4e
Routing Destination:hstaging2003.database.windows.net\\e0c5fac33b42,4082",
Expected behavior
Retries are attempted inline with the retry policy of the endpoint, in this case the default behaviour.
Actual behavior
It gives up after 7s.
Versions
Please list the version of the relevant packages or applications in which the bug exists.
NServiceBus.Persistence.Sql 8.2.0
NServiceBus.Transport.SqlServer 8.1.10
Steps to reproduce
Publish delayed messages and have a connection to SQL die just at the time of moving from the delayed queue to the non delayed queue.