Bug #110790 ExecuteReaderAsync hangs instead of cancelling query after CommandTimeout
Submitted: 24 Apr 2023 18:37 Modified: 7 Jun 2023 15:05
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.33 OS:Windows (10)
Assigned to: CPU Architecture:Any

[24 Apr 2023 18:37] Bradley Grainger
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}");
[7 Jun 2023 15:05] MySQL Verification Team
Hello Bradley Grainger,

Thank you for the bug report.
Verified as described.

Regards,
Ashwini Patil