Bug #94760 OpenAsync(CancellationToken) doesn't use the token
Submitted: 24 Mar 18:49 Modified: 25 Mar 6:23
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.15 OS:Microsoft Windows (10)
Assigned to: Daniel Valdez CPU Architecture:Other (x64)

[24 Mar 18:49] Bradley Grainger
Description:
The MySqlConnection.OpenAsync(CancellationToken) override doesn't cancel the connection when the cancellation token is cancelled.

The expectation is that cancelling the CancellationToken would stop the connection to the server. Instead, nothing happens until the Connect Timeout (default: 15 seconds) is reached.

How to repeat:
Run the following C# code:

using (var connection = new MySqlConnection("Server=www.mysql.com"))
{
	var sw = Stopwatch.StartNew();
	try
	{
		using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(2)))
			await connection.OpenAsync(cts.Token);
	}
	catch (MySqlException ex)
	{
		Console.WriteLine(ex.Message); // Unable to connect to any of the specified MySQL hosts
		Console.WriteLine(ex.Number); // 1042

		// prints 00:00:15.001, expected 00:00:02
		Console.WriteLine(sw.Elapsed);
	}
}
[25 Mar 6:23] Umesh Shastry
Hello Bradley,

Thank you for the report and test case.
Observed with VS 2017 (C#.Net) and Connector/NET 8.0.15 version.

regards,
Umesh