Description:
When CommandTimeout is set, MySqlCommand.ExecuteReaderAsync hangs forever instead of (a) cancelling the query after the CommandTimeout, or (b) returning when the command actually does finish.
The problem only occurs when using ExecuteReaderAsync, not ExecuteReader.
This is a regression from 8.0.32.1.
The expected behavior from the test program is to print the following output. This happens for 8.0.32.1 and for ExecuteReader (in 8.0.33), but not for ExecuteReaderAsync in 8.0.33. Even if the command weren't cancelled, the program should finish running after about five seconds (when SELECT SLEEP(5) finishes); however, it just hangs.
Exception 'Fatal error encountered during command execution.' after 00:00:02.0165024
ExecuteReaderAsync finished after 00:00:02.0190520
How to repeat:
Run the following C# code:
using var connection = new MySqlConnection("...");
await connection.OpenAsync();
using var command = new MySqlCommand("SELECT SLEEP(5);", connection) { CommandTimeout = 2 };
var stopwatch = Stopwatch.StartNew();
try
{
// Works; prints message: Exception 'Fatal error encountered during command execution.' after 00:00:02.0166766
// using var reader = command.ExecuteReader();
// hangs forever
using var reader = await command.ExecuteReaderAsync();
}
catch (Exception ex)
{
Console.WriteLine($"Exception '{ex.Message}' after {stopwatch.Elapsed}");
}
Console.WriteLine($"ExecuteReaderAsync finished after {stopwatch.Elapsed}");