Skip to content

Commit a258166

Browse files
committed
Don't AutoEnlist cancellation connection. Fixes #1001
1 parent b7a82b1 commit a258166

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/MySqlConnector/MySqlConnection.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,11 @@ internal void Cancel(ICancellableCommand command, int commandId, bool isCancel)
707707
try
708708
{
709709
// open a dedicated connection to the server to kill the active query
710-
var csb = new MySqlConnectionStringBuilder(m_connectionString);
711-
csb.Pooling = false;
710+
var csb = new MySqlConnectionStringBuilder(m_connectionString)
711+
{
712+
AutoEnlist = false,
713+
Pooling = false,
714+
};
712715
if (m_session.IPAddress is not null)
713716
csb.Server = m_session.IPAddress.ToString();
714717
var cancellationTimeout = GetConnectionSettings().CancellationTimeout;

tests/SideBySide/TransactionScopeTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,19 @@ public async Task CommandBehaviorCloseConnection(string connectionString)
656656
}
657657
}
658658

659+
[Theory]
660+
[MemberData(nameof(ConnectionStrings))]
661+
public async Task CancelExecuteNonQueryAsync(string connectionString)
662+
{
663+
using var connection = new MySqlConnection(AppConfig.ConnectionString + ";" + connectionString);
664+
using var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
665+
await connection.OpenAsync();
666+
667+
using var command = new MySqlCommand("DO SLEEP(3);", connection);
668+
using var tokenSource = new CancellationTokenSource(TimeSpan.FromMilliseconds(100));
669+
await command.ExecuteNonQueryAsync(tokenSource.Token);
670+
}
671+
659672
[SkippableFact(Baseline = "Multiple simultaneous connections or connections with different connection strings inside the same transaction are not currently supported.")]
660673
public void CommitTwoTransactions()
661674
{

0 commit comments

Comments
 (0)