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:
None 
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
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 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.

regards,
Umesh

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.050 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.