Skip to content

Commit cc54bc7

Browse files
committed
Set timeouts from CancellationTimeout. Fixes #951
1 parent 33023cf commit cc54bc7

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public void DoCancel(ICancellableCommand commandToCancel, MySqlCommand killComma
125125
// command would be killed (because "KILL QUERY" specifies the connection whose command should be killed, not
126126
// a unique identifier of the command itself). As a mitigation, we set the CommandTimeout to a low value to avoid
127127
// blocking the other thread for an extended duration.
128-
killCommand.CommandTimeout = 3;
129128
killCommand.ExecuteNonQuery();
130129
}
131130
}

src/MySqlConnector/MySqlConnection.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,11 +706,13 @@ internal void Cancel(ICancellableCommand command)
706706
csb.Pooling = false;
707707
if (m_session.IPAddress is not null)
708708
csb.Server = m_session.IPAddress.ToString();
709-
csb.ConnectionTimeout = 3u;
709+
var cancellationTimeout = GetConnectionSettings().CancellationTimeout;
710+
csb.ConnectionTimeout = cancellationTimeout < 1 ? 3u : (uint) cancellationTimeout;
710711

711712
using var connection = new MySqlConnection(csb.ConnectionString);
712713
connection.Open();
713714
using var killCommand = new MySqlCommand("KILL QUERY {0}".FormatInvariant(command.Connection!.ServerThread), connection);
715+
killCommand.CommandTimeout = cancellationTimeout < 1 ? 3 : cancellationTimeout;
714716
m_session.DoCancel(command, killCommand);
715717
}
716718
catch (MySqlException ex)

0 commit comments

Comments
 (0)