-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConnectionTimeout is not working #739
Comments
I see two exceptions in your log. The first takes ~19 seconds to time out:
The second appears to take ~125 seconds. I assume your expectation is that both timeouts would be much closer to five seconds.
|
I'm having similar issues calling this from within an AWS Lambda. No matter what I do, I will not get a timeout of the Open command; it will instead always timeout the Lambda script when I run it. Any tips? I even log the timeout variable, but still no luck. |
There are integration tests to ensure that MySqlConnector/tests/SideBySide/ConnectSync.cs Lines 226 to 240 in a0da796
However, it sounds like there may be some cases that aren't handled by the existing code, which may need further investigation. |
As a hint to check, this could very well be due to AWS implementation of their serverless DB. They probably have a "frontend" that is accepting the incoming connection, but because the DB "backend" is not actually running (it is being started when the call is performed) it waits on the other side after the initial connect is made. Does this make sense? |
First off, thank you @bgrainger and team very much for a great open-source connector! Sorry for the wall of text, but I wanted to share my findings as I think they should help a lot in fixing this issue. We were also seeing problems in an AWS Lambda + Aurora serverless stack, although running with a netcore3.1 custom runtime and through Pomelo's EF Core provider. This is a very niche problem but it seems to occur with Aurora Serverless, and causes our Lambdas to hit the 5 min compute limit rather than gracefully handling a DB timeout. After quite a bit of digging I was able to recreate the problem synthetically with the following steps:
The last call never completes, and never throws an exception; it blocks forever Digging through the stack frames and connector source, it seems there is no timeout for the handshake packets when connecting with TCP So, what will happen is the TCP connection is opened but the receive call for the initial server hello packet blocks indefinitely. AFAICT the offending line is in So from all that I think setting a timeout before that receive call (and other handshake calls) would fix the issue. A timeout equal to Connection Timeout would work in a pinch, but maybe better would be Thanks! Some reference:
Test static async Task Main(string[] args)
{
MySqlConnectorLogManager.Provider = new ConsoleLoggerProvider(MySqlConnectorLogLevel.Trace);
var connector = new MySqlConnection("Server=localhost;Port=3305;ConnectionTimeout=10;Command Timeout=10");
await connector.OpenAsync();
// The following line is never reached
Console.WriteLine("Connection opened");
} Log output: (this is after leaving for ~10min)
|
@DillonN Thank you for the detailed report! It sounds like I should be able to reproduce this easily (using https://github.com/mysql-net/MySqlConnector/blob/master/tests/MySqlConnector.Tests/FakeMySqlServer.cs or an even simpler server), so I'll try to look into this and fix it soon. |
@bgrainger thanks for the quick response, let me know if you need anything more |
The scenario @DillonN should be fixed in 0.63.0. @radian-jp can you confirm your original scenario is improved? |
Latency after repeated disconnections has been improved, but seems to be different from the ConnectionTimeout setting. (ConnectionTimeout= 5) [MySql.Data 8.0.19] [MySqlConnector 0.63.0] |
Success! The connection from my AWS Lambda now correctly timed out! Thank you so much for the fast response! |
Reopening as the issue @radian-jp reported needs to be investigated further. |
Commenting out the ExecuteScalar in the first post of the test code worked correctly for the timeout. |
@bgrainger I re-tested in my synthetic setup and the timeout works correctly! It will take a bit to get the change merged in our dev environment and watch for issues, but I am thinking it is fixed. So unless I come back in a couple days it is fixed on my end. Thanks again for the quick action! |
After executing ExecuteScalar and reconnecting with the network disconnected, m_socket.Receive of SocketByteHandler is called and seems to be blocking. |
If the MySqlConnection.Open method is called when the LAN cable is disconnected, it will stop for a long time.
[OS] Windows10
[DLL] MySqlConnector 0.61.0
[Framework] .NET Core 2.1
[TestCode]
[Result]
result.txt
The text was updated successfully, but these errors were encountered: