Transaction aborted

When a message cannot be handled - i.e. when we throw an exception in the message handler - we get the following exception:

NServiceBus.RecoverabilityExecutor [(null)] - Moving message '253c5778-5a92-464c-9008-af33014cc241' to the error queue 'XXX.error' because processing failed due to an exception:
System.Transactions.TransactionAbortedException: The transaction has aborted. ---> System.Data.SqlClient.SqlException: The service has encountered an error processing your request. Please try again. Error code 8522.
A severe error occurred on the current command.  The results, if any, should be discarded.
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   at System.Data.SqlClient.SqlDelegatedTransaction.SinglePhaseCommit(SinglePhaseEnlistment enlistment)
   --- End of inner exception stack trace ---
   at System.Transactions.TransactionStatePromotedNonMSDTCAborted.PromotedTransactionOutcome(InternalTransaction tx)
   at System.Transactions.CommittableTransaction.Commit()
   at System.Transactions.TransactionScope.InternalDispose()
   at System.Transactions.TransactionScope.Dispose()
   at NServiceBus.Transport.SqlServer.ProcessWithTransactionScope.<ReceiveMessage>d__1.MoveNext()
2022-10-20 10:01:44,724 INFO  XXX.XXX.EndpointSettings [(null)] - Message sent to error queue. Error: The transaction has aborted.

The message says the items is sent to the error queue, but they seem to be stuck in the SQL queue table. Anything that we may be missing here?

Hi

Could you share your handler code and the endpoint configuration code? It looks like the transaction that is shared between the business logic and the transport is rolled back/aborted but the transport is not aware of it and wants to commit it.

If you don’t want to share the code publicly, please create a support case.

Szymon