Skip to content
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

Cancellation: "Multiple simultaneous connections ... not supported when UseXaTransactions=False" #1001

Closed
Timovzl opened this issue Jun 14, 2021 · 3 comments

Comments

@Timovzl
Copy link

Timovzl commented Jun 14, 2021

With UseXaTransactions=False and TransactionScope, triggering the cancellation token during ExecuteReaderAsync leads to the following exception:

System.NotSupportedException: Multiple simultaneous connections or connections with different connection strings
inside the same transaction are not supported when UseXaTransactions=False.
at MySqlConnector.MySqlConnection.FindExistingEnlistedSession(Transaction transaction) in /_/src/MySqlConnector/MySqlConnection.cs:line 289
at MySqlConnector.MySqlConnection.OpenAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 435
at MySqlConnector.MySqlConnection.Open() in /_/src/MySqlConnector/MySqlConnection.cs:line 380
at MySqlConnector.MySqlConnection.Cancel(ICancellableCommand command, Int32 commandId, Boolean isCancel) in /_/src/MySqlConnector/MySqlConnection.cs:line 719
at MySqlConnector.MySqlCommand.Cancel() in /_/src/MySqlConnector/MySqlCommand.cs:line 98
at System.Threading.CancellationToken.<>c.<.cctor>b__26_0(Object obj)
at System.Threading.CancellationTokenSource.InternalRegister(Action`1 callback, Object stateForCallback, SynchronizationContext syncContext, ExecutionContext executionContext)
at System.Threading.CancellationToken.Register(Action`1 callback, Object state, Boolean useSynchronizationContext, Boolean useExecutionContext)
at MySqlConnector.MySqlCommand.MySqlConnector.Core.ICancellableCommand.RegisterCancel(CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlCommand.cs:line 364
at MySqlConnector.MySqlDataReader.ReadAsync(CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 43

The cancellation token was triggered due to application shutdown (SIGTERM).

The flow was as follows:

  • Construct TransactionsScope in using, with async flows enabled.
  • ExecuteReaderAsync, with CancellationToken.
  • CancellationToken requests cancellation.

I have a theory. Is it possible that the logic that handles cancellation fails to return the connection to the pool? Perhaps a rollback is then attempted, but the connection that was bound to the transaction is not available, so a new connection is attempted to be used. That would explain the exception.

I also wonder if this could be related to #745.

@bgrainger
Copy link
Member

It looks like the background connection being opened to cancel the command is automatically enlisting in the current TransactionScope.

This is not desirable, and should be trivial to bypass with AutoEnlist=false.

@Timovzl
Copy link
Author

Timovzl commented Jun 15, 2021

Nice! As always, your fast response is greatly appreciated.

@bgrainger
Copy link
Member

Fixed in 1.3.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants