| Bug #106243 | CancellationToken doesn't cancel MySqlConnection.OpenAsync | ||
|---|---|---|---|
| Submitted: | 22 Jan 2022 4:12 | Modified: | 10 Jun 2022 16:27 |
| Reporter: | Bradley Grainger (OCA) | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / NET | Severity: | S2 (Serious) |
| Version: | 8.0.28 | OS: | Windows |
| Assigned to: | CPU Architecture: | Any | |
[22 Jan 2022 7:43]
MySQL Verification Team
Hello Bradley, Thank you for the report and test case. regards, Umesh
[10 Jun 2022 16:27]
Christine Cole
Posted by developer: Fixed as of the upcoming MySQL Connector/NET 8.0.30 release, and here's the proposed changelog entry from the documentation team: Previously, it was possible to cancel the MySqlConnection.OpenAsync operation if the CancellationToken object was canceled. This fix restores the original behavior. Thank you for the bug report.

Description: Cancelling the CancellationToken passed to MySqlConnection.OpenAsync no longer cancels the operation. This is a regression from 8.0.27 How to repeat: Run the following C# code: using var connection = new MySqlConnection("..."); using var cts = new CancellationTokenSource(); cts.Cancel(); await connection.OpenAsync(cts.Token); // this throws TaskCanceledException in 8.0.27 Console.WriteLine(connection.State); // prints Open It is expected that the operation will be cancelled when the token passed to it is cancelled, particularly if it's cancelled before OpenAsync is called. Suggested fix: Return to the 8.0.27 behaviour and cancel the OpenAsync operation if the CancellationToken is cancelled.