Skip to content

Commit 50bbe31

Browse files
committed
Fix exception introduced by new logging.
1 parent 8b91dbe commit 50bbe31

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/MySqlConnector/MySqlBatch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void Prepare()
151151

152152
public Task PrepareAsync(CancellationToken cancellationToken = default) => PrepareAsync(AsyncIOBehavior, cancellationToken);
153153

154-
public void Cancel() => Connection?.Cancel(this);
154+
public void Cancel() => Connection?.Cancel(this, m_commandId, true);
155155

156156
public void Dispose()
157157
{

src/MySqlConnector/MySqlCommand.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,7 @@ private MySqlCommand(MySqlCommand other)
9595
public new MySqlParameter CreateParameter() => (MySqlParameter) base.CreateParameter();
9696

9797
/// <inheritdoc/>
98-
public override void Cancel()
99-
{
100-
Log.Info("CommandId {0} for Session{1} has been canceled via Cancel().", m_commandId, Connection?.Session.Id);
101-
Connection?.Cancel(this);
102-
}
98+
public override void Cancel() => Connection?.Cancel(this, m_commandId, true);
10399

104100
/// <inheritdoc/>
105101
public override int ExecuteNonQuery() => ExecuteNonQueryAsync(IOBehavior.Synchronous, CancellationToken.None).GetAwaiter().GetResult();
@@ -392,9 +388,8 @@ void ICancellableCommand.SetTimeout(int milliseconds)
392388

393389
private void CancelCommandForTimeout()
394390
{
395-
Log.Info("CommandId {0} for Session{1} has been canceled via command timeout.", m_commandId, Connection?.Session.Id);
396391
Volatile.Write(ref m_commandTimedOut, true);
397-
Connection?.Cancel(this);
392+
Connection?.Cancel(this, m_commandId, false);
398393
}
399394

400395
private bool IsValid([NotNullWhen(false)] out Exception? exception)

src/MySqlConnector/MySqlConnection.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,10 +694,15 @@ internal ServerSession Session
694694

695695
internal void SetSessionFailed(Exception exception) => m_session!.SetFailed(exception);
696696

697-
internal void Cancel(ICancellableCommand command)
697+
internal void Cancel(ICancellableCommand command, int commandId, bool isCancel)
698698
{
699699
if (m_session is null || State != ConnectionState.Open || !m_session.TryStartCancel(command))
700+
{
701+
Log.Info("Ignoring cancellation for closed connection or invalid CommandId {0}", commandId);
700702
return;
703+
}
704+
705+
Log.Info("CommandId {0} for Session{1} has been canceled via {2}.", commandId, m_session.Id, isCancel ? "Cancel()" : "command timeout");
701706

702707
try
703708
{
@@ -718,7 +723,7 @@ internal void Cancel(ICancellableCommand command)
718723
catch (MySqlException ex)
719724
{
720725
// cancelling the query failed; setting the state back to 'Querying' will allow another call to 'Cancel' to try again
721-
Log.Warn(ex, "Session{0} cancelling command {1} failed", m_session!.Id, command.CommandId);
726+
Log.Warn(ex, "Session{0} cancelling CommandId {1} failed", m_session!.Id, command.CommandId);
722727
m_session.AbortCancel(command);
723728
}
724729
}

0 commit comments

Comments
 (0)