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
Cancellation: "Multiple simultaneous connections ... not supported when UseXaTransactions=False" #1001
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 whenUseXaTransactions=False.atMySqlConnector.MySqlConnection.FindExistingEnlistedSession(Transactiontransaction) in /_/src/MySqlConnector/MySqlConnection.cs:line289
at MySqlConnector.MySqlConnection.OpenAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken)in/_/src/MySqlConnector/MySqlConnection.cs:line435
at MySqlConnector.MySqlConnection.Open()in/_/src/MySqlConnector/MySqlConnection.cs:line 380
at MySqlConnector.MySqlConnection.Cancel(ICancellableCommandcommand,Int32commandId,BooleanisCancel) in /_/src/MySqlConnector/MySqlConnection.cs:line719
at MySqlConnector.MySqlCommand.Cancel()in/_/src/MySqlConnector/MySqlCommand.cs:line 98
at System.Threading.CancellationToken.<>c.<.cctor>b__26_0(Objectobj)
at System.Threading.CancellationTokenSource.InternalRegister(Action`1callback,ObjectstateForCallback,SynchronizationContextsyncContext,ExecutionContextexecutionContext)
at System.Threading.CancellationToken.Register(Action`1callback,Objectstate,BooleanuseSynchronizationContext,BooleanuseExecutionContext)
at MySqlConnector.MySqlCommand.MySqlConnector.Core.ICancellableCommand.RegisterCancel(CancellationTokencancellationToken) 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.
Activity
bgrainger commentedon Jun 14, 2021
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.Don't AutoEnlist cancellation connection. Fixes #1001
Timovzl commentedon Jun 15, 2021
Nice! As always, your fast response is greatly appreciated.
bgrainger commentedon Jun 16, 2021
Fixed in 1.3.10.