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

[24 Mar 2019 18:49] Bradley Grainger
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();
		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
[25 Mar 2019 6:23] MySQL Verification Team
Hello Bradley,

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