Bug #101507 MySqlCommand.Cancel throws NullReferenceException for a Closed connection
Submitted: 8 Nov 2:06 Modified: 8 Nov 4:35
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.22 OS:Microsoft Windows (10)
Assigned to: CPU Architecture:Any

[8 Nov 2:06] Bradley Grainger
Description:
When MySqlCommand.Cancel is called for a command associated with a closed (or disposed) MySqlConnection, it throws a NullReferenceException. I would expect it to silently succeed. If an exception must be thrown, ObjectDisposedException or InvalidOperationException would be more appropriate than NullReferenceException.

System.NullReferenceException
   at MySql.Data.MySqlClient.MySqlConnection.get_ServerThread()
   at MySql.Data.MySqlClient.MySqlConnection.CancelQuery(Int32 timeout)
   at MySql.Data.MySqlClient.MySqlCommand.Cancel()

How to repeat:
var connection = new MySqlConnection("...");
var command = connection.CreateCommand();
command.Cancel();

// *** OR ***

var connection = new MySqlConnection(csb.ConnectionString);
connection.Open();
var command = connection.CreateCommand();
connection.Close();
command.Cancel();
[8 Nov 4:35] MySQL Verification Team
Hello Bradley,

Thank you for the report and test case.
Verified as described.

regards,
Umesh