Skip to content

Commit 31ca1b1

Browse files
committed
Ignore a race condition in cancellation. Fixes #1002
1 parent a258166 commit 31ca1b1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/MySqlConnector/MySqlConnection.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,13 @@ internal void Cancel(ICancellableCommand command, int commandId, bool isCancel)
723723
killCommand.CommandTimeout = cancellationTimeout < 1 ? 3 : cancellationTimeout;
724724
m_session.DoCancel(command, killCommand);
725725
}
726+
catch (InvalidOperationException ex)
727+
{
728+
// ignore a rare race condition where the connection is open at the beginning of the method, but closed by the time
729+
// KILL QUERY is executed: https://github.com/mysql-net/MySqlConnector/issues/1002
730+
Log.Info(ex, "Session{0} ignoring cancellation for closed connection.", m_session!.Id);
731+
m_session.AbortCancel(command);
732+
}
726733
catch (MySqlException ex)
727734
{
728735
// cancelling the query failed; setting the state back to 'Querying' will allow another call to 'Cancel' to try again

0 commit comments

Comments
 (0)