Skip to content

Commit

Permalink
Fix exception introduced by new logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrainger committed Mar 7, 2021
1 parent 8b91dbe commit 50bbe31
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/MySqlConnector/MySqlBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void Prepare()

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

public void Cancel() => Connection?.Cancel(this);
public void Cancel() => Connection?.Cancel(this, m_commandId, true);

public void Dispose()
{
Expand Down
9 changes: 2 additions & 7 deletions src/MySqlConnector/MySqlCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ private MySqlCommand(MySqlCommand other)
public new MySqlParameter CreateParameter() => (MySqlParameter) base.CreateParameter();

/// <inheritdoc/>
public override void Cancel()
{
Log.Info("CommandId {0} for Session{1} has been canceled via Cancel().", m_commandId, Connection?.Session.Id);
Connection?.Cancel(this);
}
public override void Cancel() => Connection?.Cancel(this, m_commandId, true);

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

private void CancelCommandForTimeout()
{
Log.Info("CommandId {0} for Session{1} has been canceled via command timeout.", m_commandId, Connection?.Session.Id);
Volatile.Write(ref m_commandTimedOut, true);
Connection?.Cancel(this);
Connection?.Cancel(this, m_commandId, false);
}

private bool IsValid([NotNullWhen(false)] out Exception? exception)
Expand Down
9 changes: 7 additions & 2 deletions src/MySqlConnector/MySqlConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,10 +694,15 @@ internal ServerSession Session

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

internal void Cancel(ICancellableCommand command)
internal void Cancel(ICancellableCommand command, int commandId, bool isCancel)
{
if (m_session is null || State != ConnectionState.Open || !m_session.TryStartCancel(command))
{
Log.Info("Ignoring cancellation for closed connection or invalid CommandId {0}", commandId);
return;
}

Log.Info("CommandId {0} for Session{1} has been canceled via {2}.", commandId, m_session.Id, isCancel ? "Cancel()" : "command timeout");

try
{
Expand All @@ -718,7 +723,7 @@ internal void Cancel(ICancellableCommand command)
catch (MySqlException ex)
{
// cancelling the query failed; setting the state back to 'Querying' will allow another call to 'Cancel' to try again
Log.Warn(ex, "Session{0} cancelling command {1} failed", m_session!.Id, command.CommandId);
Log.Warn(ex, "Session{0} cancelling CommandId {1} failed", m_session!.Id, command.CommandId);
m_session.AbortCancel(command);
}
}
Expand Down

0 comments on commit 50bbe31

Please sign in to comment.