-
Notifications
You must be signed in to change notification settings - Fork 341
InvalidOperationException rolling back transaction #745
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
Comments
This happened again:
|
Hi @bgrainger ,
The trace seems to be closely related, we are using v0.69.4 of the connector. Is this a similar issue ? How can we go about fixing this. We are unable to replicate this and are facing application restarts whenever this occurrs. Thanks. |
It does seem related, but not sure if it's exactly the same; the OP has
To be honest, a consistent repro would be great, and a PR with the fix would be even better. 😀 |
The bug can be reproed with this code: using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.FromSeconds(0.5)))
{
using (var connection = new MySqlConnection(ConnectionString))
{
connection.Open();
connection.Execute("SELECT SLEEP(1);");
}
transactionScope.Complete();
} With
With
|
@xtroncode's exception message is probably due to #867, which isn't fixed in 0.x. @xtroncode are you able to update to 1.x, or are you stuck on 0.x? |
We need to detect if the connection (that we wish to roll back) is currently being used to execute a command. If so, cancel that command, issue This is likely to be subtle and difficult, as many of those methods have not been designed for concurrent usage (from multiple threads) so there are many places where state will be getting updated, and all of them now need to be protected. |
Code that encounters this race condition with MySqlConnector is also very likely to be broken under MySql.Data, too: https://bugs.mysql.com/bug.php?id=102129 |
@bgrainger Thanks for the explanation, I'll look at the release notes and see if we can move to 1.x . |
@xtroncode Note that the underlying bug/race condition (this specific issue) isn't fixed in 1.x yet, but due to the complexity of fixing it, it probably wouldn't ever be backported to 0.x (which is why I was wondering if you were able to upgrade). |
I tried upgrading but we have some other dependency that isn't compatible with 1.x yet. So we are trying to figure why the timeout occurs or will move the transaction to a stored procedure (we use transactions in just one place). Thanks. |
Another workaround would be to switch from |
5 years later and this is still a problem it seems? I'm on MySqlConnector 2.3.7, .NET8 and getting this when the scope times out:
The exception does not get caught in the enclosing try/catch and crashes the application. Not that there would be a way to recover, but still. I have code that started in MSSQL and it'll be a rewrite to switch to basic transactions. |
I have never seen this happen. I tried the code in the log from 2020 with |
The sample code above does show the problem. That |
A recent integration test suite failed with:
At first glance, it appears that an active connection is being used to issue a
ROLLBACK
command. This will fail if the connection is already being used to execute a query.To make it work, we would need to cancel the command (i.e., issue
KILL QUERY x
on a separate connection), wait for the first connection to become idle, then execute the ROLLBACK. This could be done either by blocking, or perhaps by setting a "pending rollback" flag on the connection (that is executed when any existing command finishes running).The text was updated successfully, but these errors were encountered: