SqlClient: System.Data.SqlClient 4.8.2 throws TransactionAbortedException (the connection has been broken)

Description

After updating System.Data.SqlClient version from old 4.6.1 to latest 4.8.2 we started to see period errors like this:

System.Transactions.TransactionAbortedException: The transaction has aborted. ---> System.InvalidOperationException: The requested operation cannot be completed because the connection has been broken.

   --- End of inner exception stack trace ---
   at System.Transactions.TransactionStateAborted.EndCommit(InternalTransaction tx)
   at System.Transactions.CommittableTransaction.Commit()
   at System.Transactions.TransactionScope.InternalDispose()
   at System.Transactions.TransactionScope.Dispose()
   ...

Those exceptions happening in pure ADO.NET code with TransactionScope created with ReadCommitted isolation level, TransactionScopeOption.Required, 1 minute timeout and TransactionScopeAsyncFlowOption.Enabled.

After rolling back to System.Data.SqlClient 4.8.1 those exceptions dissapeared but we saw another new type of exceptions we’ve never seen before from cassandra driver:

Exception while trying borrow a connection from a pool

System.Net.Sockets.SocketException: Transport endpoint is not connected
   at Cassandra.Connections.HostConnectionPool.GetExistingConnections()
   at Cassandra.Connections.HostConnectionPool.BorrowExistingConnection()
   at async Cassandra.Connections.HostConnectionPool.GetConnectionFromHostAsync(?)

Downgrading back to 4.6.1 seems to fixed all issues.

Configuration

It happened on aspnet core 3.1 web applications and console netcore 3.1 applications with latest 3.1 images both running in container on Linux.

Regression?

It works on System.Data.SqlClient 4.6.1

Other information

This issue happening on heavy load application and only on production. I can’t reproduce this issue locally. I wish I could find source for System.Data.SqlClient library to see the diff for 4.8.2 version.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 40 (18 by maintainers)

Most upvoted comments

We have the same problem with Microsoft.Data.SqlClient under Net 5.0. With heavy parallel load the connection pooling/transaction handling seems to break down. With the attached solution the problem can be reproduced. It runs heavy load in cycles. Sometimes you have to wait till cycle 50 or so for the problem to occur, but it will appear consistently. SQLProblem.zip I tried to dig deeper, but unfortunately the System.Transactions.TransactionEventSource is not working at the moment.

Hi, I’ve managed to try the patch both with the reproduction and within our application (where we originally encountered with this problem), and it works perfectly. Thanks a lot for the fix.

AFAIK System.Data.SqlClient is not open sourced but source open at

It absolutely was and was part of this repository. It was removed in favour of the Microsoft version as I said earlier. To see the code you’ll have to look into the history prior to it’s removal.