Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MySQLConnection Timeout on open #1086

Unanswered
Tobist asked this question in Q&A
Nov 23, 2021 · 1 comments · 7 replies
Discussion options

Behavior

I've got a strange behavior on one of my systems. I am trying to connect to the mysql-server on a remote system. After 15 seconds (command timeout) I get a timeout exception. On the other systems which are likely the same, the same code works.

A closer look into the sent messages with wireshark shows that the Client(MySQLConnector) and Server (MySQL5.7) are giving each other Certificates, Handshakes and the "new session Ticket". But the Open method of the MySQLConnection-class does not continue.

Is there anything about the server configuration I forgot? Anything in the connectionstring I should add?

If you need furthermore Information let me know.

System Components

Both Systems are Windows 10.0.19043, x64 with an installed .NET Framework 4.8.04084

Remote Target MySQL Server:

  • Version: 5.7.36
  • Host OS: Ubuntu 20.04.3 LTS (by WSL)

Application:

  • tested MySQLConnector Versionen 1.0.1.0 | 2.0
  • Connectionstring: Server=xxx.xxx.xxx.xxx;Database=MySQL_TestDB;Port=3306;Uid=Username;Pwd=myPassword;

Exception

Message
Connect Timeout expired.

Inner Exception
Unable to connect to any of the specified MySQL hosts.

Stacktrace

at MySqlConnector.MySqlConnection.<CreateSessionAsync>d__117.MoveNext() in //src/MySqlConnector/MySqlConnection.cs:line 843\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\TaskAwaiter.cs:line 184\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\TaskAwaiter.cs:line 157\r\n
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()\r\n
at MySqlConnector.MySqlConnection.<OpenAsync>d__27.MoveNext() in /
/src/MySqlConnector/MySqlConnection.cs:line 407\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\TaskAwaiter.cs:line 184\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in f:\dd\ndp\clr\src\BCL\system\runtime\compilerservices\TaskAwaiter.cs:line 157\r\n
at MySqlConnector.MySqlConnection.Open() in /_/src/MySqlConnector/MySqlConnection.cs:line 365\r\n

Code

C# console application:

MySqlConnection conn = new MySqlConnection(connectionstring);
try
{
 Console.WriteLine(sw.Elapsed.ToString() + ": First Connection establish...");
 conn.Open();
 Console.WriteLine(sw.Elapsed.ToString() + ": First Connection established. State: " + conn.State.ToString());
 conn.Close();
 Console.WriteLine(sw.Elapsed.ToString() + ": First Connection closed. State: " + conn.State.ToString());
}
catch(Exception ex)
{
 Console.WriteLine(sw.Elapsed.ToString() + ": Exception thrown:" + ex.Message);
} 

Output:

00:00:00.0002621: First Connection establish...

00:00:15.0468347: Exception thrown:Connect Timeout expired.

You must be logged in to vote

Replies: 1 comment 7 replies

Comment options

A closer look into the sent messages with wireshark shows that the Client(MySQLConnector) and Server (MySQL5.7) are giving each other Certificates, Handshakes and the "new session Ticket".

Can you share a packet capture from a failing connection? Is it captured client-side or server-side? (Or do you have both?)

You must be logged in to vote
7 replies
Comment options

Yes that's the expected behavior. The Server closes the connection due to the set timeouts. In this ws record the server closes the connection after 10 seconds when it is not used.

The Problem is, that 10 seconds before conn.Open(); does not continue after getting the "New Session Ticket" (913). Therefore I cannot continue in my code with a query execution or something like that.

This one is from a working system. It looks nearly the same until No. 336. (In this case I am connecting to a mysql version 8)

image

Comment options

For the non-working scenario, does it help to set Ssl Mode=None on the client's connection string?

I'm wondering if it's some kind of problem negotiating TLS ciphers (yet one that doesn't result in an exception). You could try forcing TLS 1.2 with TLSVersion = TLS 1.2 (https://mysqlconnector.net/connection-options/#TlsVersion) or explicitly specify TlsCipherSuites (https://mysqlconnector.net/connection-options/#TlsCipherSuites). You can get the cipher suite from a working connection with SELECT * FROM performance_schema.session_status WHERE VARIABLE_NAME = 'Ssl_cipher';.

Comment options

With SSL Mode=None, there is no error anymore.
TLS Version= TLS 1.2 does not help.

I will investigate more on the SSL Configuration.

Comment options

Just to confirm: you're running Windows 10 21H1 on the client with .NET Framework 4.8? I'm not aware of any TLS negotiation problems associated with that platform.

Are there clients that can connect successfully to that server? Do they have a different client OS or .NET version?

Is it at all possible that you ever changed AppContext switches or registry values that affect TLS on the non-working client? https://docs.microsoft.com/en-us/dotnet/framework/network-programming/tls#configuring-security-via-appcontext-switches-for-net-framework-46-or-later-versions

Comment options

Yes its a Windows 10 Device, but LTSC and .NET Framework 4.8. I will check that TLS settings soon but that's already a good hint. Thanks a lot for your help!

The App Context is not switched. For testing purposes I just used a brand new .net 4.8 console application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /