-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
5.1.2 + System.Transactions with volatile resource manager gives "The operation is not valid for the current state of the enlistment" exceptions under concurrent load #2262
Comments
Have you tested 5.1.2 ? |
Yes, sorry - I should have included that information. I've tested the latest version also, 5.1.2. I'll edit and add that to the initial post for clarity. |
Sharing the result from my runs:
|
/cc @roji |
Just a standard race condition in SqlClient, nothing new here. Short version, SqlClient manages to mix two different transactions together, which results in it dooming the connection. First, SqlClient tries to cleanup connection on transaction commit, which happens with this stacktrace: Now, there is also another cleanup, though this time it's transaction cleanup, which is called when transaction is committed through a callback: Now, here's the problem. The first cleanup returns the connection from the transaction pool to the default pool, allowing other threads to start using that connection. But, due to callback never being removed, the second cleanup detects another transaction and ultimately dooms that connection, which leads to various errors. Line 433 in 04b531b
|
Looks like this was fixed with the fix in the following PR: #2301 Thanks @DavoudEshtehari! |
Describe the bug
After upgrading to EFCore 8 from EFCore 6 we started seeing "System.InvalidOperationException: The operation is not valid for the current state of the enlistment." errors in our logfiles.
A bit of research has isolated the issue to the increased version of the SqlClient transitive dependency, specifically the update from 5.0.1 to 5.0.2. The issue is present on the latest 5.1.2 version also. Included below is a sample application that reproduces the issue.
In low volume testing the issue didn't appear, but under moderate load appeared reliably.
The full exception we are seeing is below:
To reproduce
A complete console app is shown below that reproduces the issue reliably. Swapping between the two referenced versions of Microsoft.Data.SqlClient should demonstrate it working or failing in 5.0.1 and 5.0.2 repectively.
Expected behavior
The same behaviour in 5.0.2 and greater as in 5.0.1.
Further technical details
Microsoft.Data.SqlClient version: 5.0.2 / 5.1.2
.NET target: net8
SQL Server version: SQL Server 2016/2022
Operating system: net8 debian docker image & Windows 11
Additional context
Currently this prevents us migrating to any EFCore versions > 7.0.5 since they all require a SqlClient dependency > 5.0.1
The text was updated successfully, but these errors were encountered: