Bug #110791 OpenAsync(CancellationToken) doesn't throw for cancelled token
Submitted: 24 Apr 2023 18:51 Modified: 13 Mar 20:17
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Can't repeat Impact on me:
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.33 OS:Windows (10)
Assigned to: CPU Architecture:Any

[24 Apr 2023 18:51] Bradley Grainger
If MySqlConnection.OpenAsync(CancellationToken) is called with a cancelled CancellationToken, and if there is a ready connection in the pool, the pooled connection is returned. The expectation is that any method called with a cancelled CancellationToken will throw a TaskCanceledException.

This was fixed in 8.0.30 for bug #106243 but now regressed in 8.0.33.

How to repeat:
Run the following C# code. Expectation is that an exception is thrown from the last line, but it is not.

using var connection = new MySqlConnection("...");

using var cts = new CancellationTokenSource();
await connection.OpenAsync(cts.Token);
[2 May 2023 5:56] MySQL Verification Team
Hello Bradley Grainger,

Thank you for the bug report.
Verified as described.

Ashwini Patil
[13 Mar 17:08] Filipe Silva
Could not be reproduced in Connector/NET 8.2.0.

Please reopen or file a new bug if the problem persists.
[13 Mar 20:17] Bradley Grainger
I can repro the problem with MySql.Data 8.3.0 using the code in the original bug report.

The last line should throw an exception, but it doesn't.

Note: it is necessary to have an open connection in the pool to reproduce the bug. Opening a new connection with a cancelled CancellationToken will throw an exception, as expected.