Search code examples
c#.netsql-server

ThreadAbortException out of nowhere


We are currently experiencing some strange behaviour.

A ThreadAbortException that appears out of nowhere interrupts the application (IIS with .NET Framework 4.8) and leaves it in an state where no new database connection can be opened.


System.Threading.ThreadAbortException: Der Thread wurde abgebrochen.
   bei SNIReadSyncOverAsync(SNI_ConnWrapper* , SNI_Packet** , Int32 )
   bei SNINativeMethodWrapper.SNIReadSyncOverAsync(SafeHandle pConn, IntPtr& packet, Int32 timeout)
   bei System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync()
   bei System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket()
   bei System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer()
   bei System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte& value)
   bei System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   bei System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   bei System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
   bei System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
   bei System.Data.SqlClient.SqlInternalTransaction.Commit()
   bei System.Data.SqlClient.SqlTransaction.Commit()

That seems to happen with multiple threads and distinct databases the same time. We need to do an IISRESET to get over this.

Do you have some idea what the root cause could be?


Solution

  • It's hard to guess without seeing the code you are running, there might might be some other issue that is getting covered by this exception. there might be a timeout at some level, or some misuse of threading/async code. I can see that the exception occurred upon a commit (if it's manual, or in TransactionScope I'd ensure the connection is still active, nothing got disposed) so I'd personally start troubleshooting from SQL Server side running a Profiler, then looked for timeouts, or any threading issues (abandoned async task, that's not awaited, unhandled exception in a thread and stuff like that)