Bug #86009 Connector connection times-out after command completes
Submitted: 19 Apr 2017 16:28 Modified: 21 Apr 2017 9:51
Reporter: Matt Houser Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.9.9 OS:Windows
Assigned to: CPU Architecture:Any
Tags: timeout

[19 Apr 2017 16:28] Matt Houser
Description:
Issuing a long-running command to MySQL server results in a client timeout receiving result. But the timeout occurs on the client AFTER the command completes on the server.

For example, issuing "SELECT SLEEP (45)" to the server. The command takes 45 seconds on the server while monitoring "SHOW PROCESS LIST".

But the client will wait for the result for 56 seconds, then issue a timeout exception.

If I add "Default Command Timeout=60" to the connection string, then the command completes OK after 45 seconds.

How to repeat:
Run the attached program. It runs the following command:

SELECT SLEEP (45);

The results are:

Error: MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.TimeoutException: Timeout in IO operation
   at MySql.Data.MySqlClient.TimedStream.StopTimer()
   at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.ExceptionInterceptor.Throw(Exception exception)
   at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex)
   at MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(Exception ex)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at MySqlTimeout1.Program.ExecuteQuery(String connectionString) in d:\Users\matt\Documents\Visual Studio 2013\Projects\MySqlTimeout1\MySqlTimeout1\Program.cs:line 50
   at MySqlTimeout1.Program.Main(String[] args) in d:\Users\matt\Documents\Visual Studio 2013\Projects\MySqlTimeout1\MySqlTimeout1\Program.cs:line 20
Execution Time: 00:00:56.5968123
Press Enter to continue...

Suggested fix:
With a default command timeout of 30 seconds, the connector should throw the exception after 30 seconds.
[19 Apr 2017 16:29] Matt Houser
Demonstration Program

Attachment: Program.cs (text/plain), 1.36 KiB.

[21 Apr 2017 9:51] Chiranjeevi Battula
Hello  Matt Houser,

Thank you for the bug report and test case.
Verified this behavior on Visual Studio 2013 (C#.Net) and Connector/NET 6.9.9 version.

Thanks,
Chiranjeevi.
[21 Apr 2017 9:52] Chiranjeevi Battula
Error: MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.TimeoutExcepti
on: Timeout in IO operation
   at MySql.Data.MySqlClient.TimedStream.StopTimer()
   at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
   at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.ExceptionInterceptor.Throw(Exception exception)
   at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex)
   at MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(Exception ex)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at _86010.Program.ExecuteQuery(String connectionString) in d:\Projects\86010\86010\Program.cs:line 51
   at _86010.Program.Main(String[] args) in d:\Projects\86010\86010\Program.cs:line 21
Execution Time: 00:00:56.7784942
Press Enter to continue...