Bug #82365 Command Timeout 1 second takes 3 seconds to timeout
Submitted: 27 Jul 2016 21:59 Modified: 1 Aug 2016 5:46
Reporter: Tasso Tasso Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.9.9 OS:Microsoft Windows
Assigned to: CPU Architecture:Any
Tags: command timeout, timeout

[27 Jul 2016 21:59] Tasso Tasso
Description:
Hi,

When I set command timeout to 1s and run a query that take more than 1s, it takes 3s or more to return an timeout error.

I test it with 10s too and it takes 20s to return an error.

How to repeat:
1. Create a procedure that takes more then 3s to return all data:
CREATE PROCEDURE timeout()
BEGIN
  SELECT SLEEP(5);
END

2. Execute the follow command on .Net:
var st = new Stopwatch();
try
{
using (var cnn = new MySqlConnection("Server=127.0.0.1;Database=[database];Uid=[user];Pwd=[pwd];"))
	{
		cnn.Open();
		var command = new MySqlCommand("call timeout();", cnn);
		command.CommandTimeout = 1;
		st.Start();
		var reader = command.ExecuteNonQuery();
		st.Stop();
		Console.WriteLine("OK");
		Console.WriteLine(st.ElapsedMilliseconds);
	}
}
catch (Exception)
{
	st.Stop();
	Console.WriteLine("EX");
	Console.WriteLine(st.ElapsedMilliseconds);
}

It'll take 3s or more to return an error.

Suggested fix:
I debug MySql source code and check that the error is on file \MySql.Data\common\MyNetworkStream.cs

The method Read() don't throw a timeout error on first try, because it have a const MaxRetryCount=2 and method HandleOrRethrowException() are returning no exception.

line 86:  else if (IsTimeoutException(socketException))
line 87:  {
line 88:    return;
line 89:    //throw new TimeoutException(socketException.Message, e);
line 90:  }
[1 Aug 2016 5:46] Chiranjeevi Battula
Hello Tasso Tasso,

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.
[1 Aug 2016 5:48] Chiranjeevi Battula
Screenshot

Attachment: 82365.JPG (image/jpeg, text), 192.18 KiB.