You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Data.SqlClient 4.8.2 throws TransactionAbortedException (the connection has been broken) #729
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.
The System version the library has been frozen and moved out of this repository in favour of Microsoft.Data.SqlClient https://github.com/dotnet/SqlClient which can be versioned separately. It contains fixes and improvements beyond those present in the framework provided versions. If possible give it a try and see if the behaviour you're seeing has already been resolved.
It's part of the framework so it doesn't get it's own update schedule. You probably want to review all the pull requests which targeted files in that project.
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.
The desktop version was distinct from the core version. This repo only contained the core version.
The code is still here but not current which I why I say you'll need to look through the repo history to look at it. You can look back at any file that has ever existed by reviewing the git history but because it isn't currently being build and shipped it's not visible in the current master.
The code was forked into Microsoft.Data.SqlClient which also contains the desktop version. The Microsoft version supercedes the System version and is versioned independently so it can be updated without a framework update. It contains performance improvements new features and bug fixes that may not be ported back to core or desktop verisons.
Thanks.
I totally misunderstood this issue. After reading 4.6.1 and 4.8.2 I thought it is all about .NET Framework - but it isn't. Sorry for the confusion.
I would gladly, but I'm afraid I can't - the code is simple ADO.NET update but something could be with the all other stuff microservice doing (heavy CPU usage due to image resizing on Skia + cassandra and rabbitmq libraries connected to servers).
Ok, I'll try to form a repro based on provided info.
Could you also confirm if your connection is a pooled connection or pooling is disabled?
Does changing that make any difference?
And also do you also know why the transaction aborts at the first place? Are there failing commands or it's something else? Have you been able to gather it from logs and is it possible to prevent the transaction abort?
Could you also confirm if your connection is a pooled connection or pooling is disabled?
It's default connection string so it's pooled by default (if I'm not mistaken).
The only thing that changed - max pool size. So connection string looks like this: server=my.server.name; database=MyDatabase; User ID=MyUser; Password=mypassword; Max Pool Size=500
Does changing that make any difference?
Before I tested it, just to clarify - should I just add "Pooling=false" or also change min/max pool size in connection string?
And also do you also know why the transaction aborts at the first place? Are there failing commands or it's something else? Have you been able to gather it from logs and is it possible to prevent the transaction abort?
I think it doesn't aborts at all. Because otherwise there should be warning about transaction in not active state before commit.
I think it doesn't aborts at all. Because otherwise there should be warning about transaction in not active state before commit.
There's certainly an abort triggered somewhere, otherwise you'd never run into this issue, since the change in last release was made specifically on "Transaction Abort" callback API.
You should be able to capture SQL Profiler traces for "Transaction" > "DTC Transaction" events to see which "Application" triggers "Transaction Aborted" events. You should notice something like below in SQL profiler traces:
We started getting the same error in .Net Framework 4.8 application under high load (lots of parallel user sessions execute database queries) after upgrade of Microsoft.Data.SqlClient from 1.1.2 to 1.1.3.
Input conditions look the same as in the issue's description. All commands are executed wrapped by a TransactionScope and using connections from ConnectionPool, smth like:
using(vartransactionScope=DataAccessFactory.Current.CreateTransactionScope()){using(varconnection=DataAccessFactory.Current.CreateConnection()){// create and execute command ...}transactionScope.Complete();}
Update:
Looks like disabling of pooling fixes the issue, but it is not a good solution from performance perspective.
Meanwhile, adding the next code in the SqlDelegatedTransaction.TransactionEnded method looks strange considering if a transaction is successfully committed: (commit 0b20c3b)
// Safest approach is to doom this connection, whose transaction has been aborted externally.// If we want to avoid dooming the connection for performance, state needs to be properly restored. (future TODO)connection.DoomThisConnection();
Having the same problem here with .NET Framework 4.8 and Microsoft.Data.SqlClient 2.1.1
transaction = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
{
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted,
}, TransactionScopeAsyncFlowOption.Enabled);
MSDTC is used, connection pooling is used, SqlConnection is open and closed for every command
at System.Transactions.TransactionStateAborted.EndCommit(InternalTransaction tx)
at System.Transactions.CommittableTransaction.Commit()
at System.Transactions.TransactionScope.InternalDispose()
at System.Transactions.TransactionScope.Dispose()
at Robin.Bll.RunManager.CompleteTransaction()
Is it possible to create a repro application to mimic your scenarios where exception occurs? That would help us in understanding more about your usecase.
The closing of Connection happens only on Transaction Abort event, and that's important to do because the driver does not lose reference to old transaction and continues to reattach it for next connection. If there's a server side delay to abort old transaction, server accepts that request. This in turn causes a security issue since whenever the transaction does end on the server side, the remaining queries on the new connection execute with implicit transactions.
We may have to look at why an aborted transaction is being committed by your application.
Is it possible to create a repro application to mimic your scenarios where exception occurs? That would help us in understanding more about your usecase.
The closing of Connection happens only on Transaction Abort event, and that's important to do because the driver does not lose reference to old transaction and continues to reattach it for next connection. If there's a server side delay to abort old transaction, server accepts that request. This in turn causes a security issue since whenever the transaction does end on the server side, the remaining queries on the new connection execute with implicit transactions.
We may have to look at why an aborted transaction is being committed by your application.
Thx for being willing to look at it.
It will be difficult to send a repro as it's a complete engine running procedures on a database.
Our .NET 4.8 application runs for days on .NET 4.8 System.Data.SqlClient. (No transactions aborted)
When only upgrading client to Microsoft.Data.SqlClient (of course in the whole application) we get this rather fast.
Will talk with client if it's worth the effort...
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.
Reacted by Ferenc Vizkeleti, Brett Wilson, Adrian and Nikita Kobzev
We have a potential fix for this issue in PR #1042.
I've tested the PR with the repro "SQLproblem" as well from #729 (comment) and this issue seems to be solved. Would appreciate your feedback if you could test and confirm the fix from this package: Build Artifacts
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.
Closing this issue as fixed has been merged for main(3.0), 2.1 and 1.1 servicing.
Next releases will contain fix for this issue.
Thx for finding a solution.
Not so clear how this will be released.
The title reads System.Data.SqlClient 4.8.2 will this be version 4.8.3 or will this not be serviced?
Because the merging/servicing you mention here is for Microsoft.Data.SqlClient?
Activity
Wraith2 commentedon Sep 12, 2020
The System version the library has been frozen and moved out of this repository in favour of Microsoft.Data.SqlClient https://github.com/dotnet/SqlClient which can be versioned separately. It contains fixes and improvements beyond those present in the framework provided versions. If possible give it a try and see if the behaviour you're seeing has already been resolved.
MichaelLogutov commentedon Sep 13, 2020
Does it requires rewriting all namespaces Microsoft.*? Because we can't afford such rework in our libraries and all microservices.
Wraith2 commentedon Sep 13, 2020
It does. You should probably consider introducing abstractions in your codebase to avoid such things causing agility limitations.
MichaelLogutov commentedon Sep 13, 2020
Well, it's not that simple when you have large code base and 20 product team developers.
Can I see the source code or at least changelog of what been changed in 4.8.2?
devsko commentedon Sep 13, 2020
Maybe these help
https://github.com/microsoft/dotnet/tree/master/releases
https://referencesource.microsoft.com/#System.Data
MichaelLogutov commentedon Sep 14, 2020
Thanks. I can see the source now but I can't seems to see the changes in 4.8.2
https://github.com/microsoft/dotnet/tree/master/releases do not seems to have release notes for individual nuget packages like System.Data.SqlClient. Or I'm missing something?
Wraith2 commentedon Sep 14, 2020
It's part of the framework so it doesn't get it's own update schedule. You probably want to review all the pull requests which targeted files in that project.
MichaelLogutov commentedon Sep 14, 2020
I couldn't find the source code in github for System.Data.SqlClient. I saw only System.Data.Common
devsko commentedon Sep 14, 2020
AFAIK System.Data.SqlClient is not open sourced but source open at https://referencesource.microsoft.com/#System.Data as mentioned above.
Wraith2 commentedon Sep 14, 2020
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.
devsko commentedon Sep 14, 2020
@Wraith2 Just curious. It was the same code for core / desktop? Where lives the System.Data.SqlClient desktop code now?
Wraith2 commentedon Sep 14, 2020
The desktop version was distinct from the core version. This repo only contained the core version.
The code is still here but not current which I why I say you'll need to look through the repo history to look at it. You can look back at any file that has ever existed by reviewing the git history but because it isn't currently being build and shipped it's not visible in the current master.
The code was forked into Microsoft.Data.SqlClient which also contains the desktop version. The Microsoft version supercedes the System version and is versioned independently so it can be updated without a framework update. It contains performance improvements new features and bug fixes that may not be ported back to core or desktop verisons.
devsko commentedon Sep 14, 2020
Thanks.
I totally misunderstood this issue. After reading 4.6.1 and 4.8.2 I thought it is all about .NET Framework - but it isn't. Sorry for the confusion.
cheenamalhotra commentedon Sep 14, 2020
Tagging @saurabh500 @corivera for System.Data.SqlClient (.Net Framework)
14 remaining items
MichaelLogutov commentedon Oct 9, 2020
I would gladly, but I'm afraid I can't - the code is simple ADO.NET update but something could be with the all other stuff microservice doing (heavy CPU usage due to image resizing on Skia + cassandra and rabbitmq libraries connected to servers).
cheenamalhotra commentedon Oct 9, 2020
Ok, I'll try to form a repro based on provided info.
Could you also confirm if your connection is a pooled connection or pooling is disabled?
Does changing that make any difference?
And also do you also know why the transaction aborts at the first place? Are there failing commands or it's something else? Have you been able to gather it from logs and is it possible to prevent the transaction abort?
MichaelLogutov commentedon Oct 12, 2020
It's default connection string so it's pooled by default (if I'm not mistaken).
The only thing that changed - max pool size. So connection string looks like this:
server=my.server.name; database=MyDatabase; User ID=MyUser; Password=mypassword; Max Pool Size=500Before I tested it, just to clarify - should I just add "Pooling=false" or also change min/max pool size in connection string?
I think it doesn't aborts at all. Because otherwise there should be warning about transaction in not active state before commit.
cheenamalhotra commentedon Oct 13, 2020
Just changing "Pooling = false" should disable it.
cheenamalhotra commentedon Oct 13, 2020
There's certainly an abort triggered somewhere, otherwise you'd never run into this issue, since the change in last release was made specifically on "Transaction Abort" callback API.
You should be able to capture SQL Profiler traces for "Transaction" > "DTC Transaction" events to see which "Application" triggers "Transaction Aborted" events. You should notice something like below in SQL profiler traces:
wolgasster commentedon Jan 14, 2021
We started getting the same error in .Net Framework 4.8 application under high load (lots of parallel user sessions execute database queries) after upgrade of Microsoft.Data.SqlClient from 1.1.2 to 1.1.3.
Input conditions look the same as in the issue's description. All commands are executed wrapped by a TransactionScope and using connections from ConnectionPool, smth like:
Update:
Looks like disabling of pooling fixes the issue, but it is not a good solution from performance perspective.
Meanwhile, adding the next code in the SqlDelegatedTransaction.TransactionEnded method looks strange considering if a transaction is successfully committed: (commit 0b20c3b)
+@cheenamalhotra @David-Engel
dotWils commentedon Feb 1, 2021
Having the same problem here with .NET Framework 4.8 and Microsoft.Data.SqlClient 2.1.1
transaction = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
{
IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted,
}, TransactionScopeAsyncFlowOption.Enabled);
MSDTC is used, connection pooling is used, SqlConnection is open and closed for every command
at System.Transactions.TransactionStateAborted.EndCommit(InternalTransaction tx)
at System.Transactions.CommittableTransaction.Commit()
at System.Transactions.TransactionScope.InternalDispose()
at System.Transactions.TransactionScope.Dispose()
at Robin.Bll.RunManager.CompleteTransaction()
cheenamalhotra commentedon Feb 1, 2021
Hi @wolgasster @dotWils
Is it possible to create a repro application to mimic your scenarios where exception occurs? That would help us in understanding more about your usecase.
The closing of Connection happens only on Transaction Abort event, and that's important to do because the driver does not lose reference to old transaction and continues to reattach it for next connection. If there's a server side delay to abort old transaction, server accepts that request. This in turn causes a security issue since whenever the transaction does end on the server side, the remaining queries on the new connection execute with implicit transactions.
We may have to look at why an aborted transaction is being committed by your application.
dotWils commentedon Feb 2, 2021
Thx for being willing to look at it.
It will be difficult to send a repro as it's a complete engine running procedures on a database.
Our .NET 4.8 application runs for days on .NET 4.8 System.Data.SqlClient. (No transactions aborted)
When only upgrading client to Microsoft.Data.SqlClient (of course in the whole application) we get this rather fast.
Will talk with client if it's worth the effort...
csnemes commentedon Apr 7, 2021
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.
cheenamalhotra commentedon Apr 20, 2021
@csnemes @dotWils @wolgasster @MichaelLogutov
We have a potential fix for this issue in PR #1042.
I've tested the PR with the repro "SQLproblem" as well from #729 (comment) and this issue seems to be solved. Would appreciate your feedback if you could test and confirm the fix from this package: Build Artifacts
Thank you
csnemes commentedon Apr 26, 2021
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.
cheenamalhotra commentedon Apr 28, 2021
Closing this issue as fixed has been merged for main(3.0), 2.1 and 1.1 servicing.
Next releases will contain fix for this issue.
dotWils commentedon May 7, 2021
Thx for finding a solution.
Not so clear how this will be released.
The title reads System.Data.SqlClient 4.8.2 will this be version 4.8.3 or will this not be serviced?
Because the merging/servicing you mention here is for Microsoft.Data.SqlClient?