Description:
This bug report is the same as #115572.
https://bugs.mysql.com/bug.php?id=115572
#115572 was closed without being fixed, so I am submitting it again.
(Sorry if this violates any rules.)
Connector version:9.4.0
.NET 9.0
The driver can throw an unhandled exception if the ConnectionTimeout expires during the AuthenticateAsClient part of the SSL initialization. This exception cannot be caught by the client and thus causes an application crash. (see detailed description below)
Expectations: Connector does not throw exceptions that cannot be handled.
Detailed description:
In Driver.cs->CreateAsync() a CancellationTokenSource (named connTimeoutSource) gets created that will be canceled after the connectionTimout has expired. The token from this connTimeoutSource is then linked to a general CancellationToken that is passed around during the connection-logic.
This token eventually ends up in Ssl.cs->StartSSLAsync(), right before starting the AuthenticateAsClientAsync() the Cancellationtoken gets used to register a callback that throws an IOException.
However if this token is cancelled by the timeout from the connTimeoutToken, This exception ends up on a timerthread and is not caught, leading to a crash of the application.
https://github.com/mysql/mysql-connector-net/blob/07b692810f368a9009e74bb462670015c37727be...
------------
We are experiencing this crash sometimes.
In certain environments, our application runs from locations that are physically far from the MySQL server. Because of this distance, the network can sometimes be unstable, and when that happens, it seems that a timeout occurs during the SSL process, which causes the app to crash.
I understand you might be busy and may not be able to look into this issue right away.
I would really appreciate it if you could let me know if there are any plans to address this problem.
If there is anything I can do on my end to work around this issue, I would also appreciate any advice.
Thank you for your time, and I look forward to your response.
How to repeat:
Requires external tools to simulate properly.
1. Configure clumsy with the following settings
-Filter "tcp.DstPort == {PORT} and tcp.PayloadLength >= 147" (basically TLS client hello)
- Enable drop on inbound/outbound with 100% chance
2. Connect a MySQL database with SSLMode=Preferred
3. Repeat MySqlConnection.Open() And MySqlConnection.Close()
4. Observe the unhandled exception.
Suggested fix:
Do not throw exceptions in the CancellationToken.Register function. Use other methods to properly detect if the timeout passed and throw the exception on the thread that called the Open().