Bug #116757 SSL MySQL Connection Timeout Causes Application Crash Without Exception
Submitted: 22 Nov 2024 14:21 Modified: 27 Nov 2024 16:27
Reporter: ahmed taha Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:9.1 OS:Windows (11)
Assigned to: Filipe Silva CPU Architecture:Any

[22 Nov 2024 14:21] ahmed taha
Description:
When establishing an SSL MySQL connection in the application, a timeout scenario leads to a complete application crash without throwing a catchable exception. This behavior persists even when the connection attempt is wrapped within a try-catch block. Debugging reveals an exception trace related to CancellationTokenSource. The application fails silently, leaving no opportunity for proper exception handling or recovery.

mscorlib.dll!System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(bool throwOnFirstException) Line 445 C#
mscorlib.dll!System.Threading.CancellationTokenSource.NotifyCancellation(bool throwOnFirstException) Line 376 C#
mscorlib.dll!System.Threading.CancellationTokenSource.TimerCallbackLogic(object obj) Line 247 C#
mscorlib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 515 C#
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 486 C#
mscorlib.dll!System.Threading.TimerQueueTimer.CallCallback() Line 200 C#
mscorlib.dll!System.Threading.TimerQueueTimer.Fire() Line 158 C#
mscorlib.dll!System.Threading.TimerQueue.FireNextTimers() Line 252 C#

How to repeat:
Steps to Reproduce
Establish a MySQL connection using SSL with the MySQL Connector/Driver 9.1.
Introduce network latency or simulate a timeout condition during the connection attempt.
Observe that no exception is caught in the try-catch block, and the application crashes.
Expected Behavior
An exception should be thrown in the event of a connection timeout, allowing it to be handled within the try-catch block for proper application recovery.

Suggested fix:
Investigate why the exception is not being propagated to the try-catch block.
Ensure that timeout-related exceptions are properly thrown and catchable during SSL connection attempts.
[22 Nov 2024 16:43] MySQL Verification Team
HI Mr. taha,

Thank you for your bug report.

However, let us inform you that this is a forum for the reports with fully repeatable test cases. Each of this test cases should consist  of a set of SQL statements, plus (in your case) a source of the program that you used to get a problem.

Next, this does not look at all like Connector/C problem ....... Are you sure that it is our C API and not C/C++ or something else ???

Last, but not least, you have obviously hit one of many timeouts that exist in MySQL. Each of these timeouts is configurable, as described in our Reference Manual, found on htttps://dev.mysql.com.

Here is a list of some timeouts that you might have hit:

connect-timeout                                              10
delayed-insert-timeout                                       300
interactive-timeout                                          28800
lock-wait-timeout                                            31536000
net-read-timeout                                             30
net-write-timeout                                            60
port-open-timeout                                            0
replica-net-timeout                                          60
rpl-stop-replica-timeout                                     31536000
rpl-stop-slave-timeout                                       31536000
slave-net-timeout                                            60
ssl-session-cache-timeout                                    300
wait-timeout                                                 28800

Can't repeat.
[22 Nov 2024 20:30] ahmed taha
sorry it was connector.Net
[24 Nov 2024 12:16] ahmed taha
ConnectionTimeOut with ssl in .Net connector 9.1

Do i have to report the bug again or changing the Category will be enough
[25 Nov 2024 10:39] MySQL Verification Team
Hi Mr. taha,

There is no need to create a separate bug report.

However, there is a need for a fully repeatable test case, as described.

Without it, we can not proceed with your report.

Can't repeat.
[26 Nov 2024 4:59] Bradley Grainger
This sounds a lot like bug #110789 and may be a duplicate of that issue.
[26 Nov 2024 10:53] MySQL Verification Team
We can not proclaim any report a duplicate, without a proper test case.
[27 Nov 2024 13:32] ahmed taha
public void TestMySqlConnection()
{
    // Set a very short connection timeout (e.g., 2 seconds)
    string connectionString = "Server=your_mysql_server;Port=3306;Database=testdb;User ID=your_user;Password=your_password;SslMode=Required;ConnectionTimeout=2;";

    try
    {
        Console.WriteLine("Attempting to connect...");
        using (var connection = new MySqlConnection(connectionString))
        {
            connection.Open();
            Console.WriteLine("Connected successfully.");
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Caught exception: " + ex.Message);
        Console.WriteLine("Exception Details: " + ex);
    }

    Console.WriteLine("Execution completed.");
}

Introduce network latency or simulate a timeout condition during the connection attempt.

The application will crush
[27 Nov 2024 14:28] MySQL Verification Team
Hi Mr. Taha,

Thank you for the test case.

Our C/NET team will take a look at it ......
[27 Nov 2024 16:16] ahmed taha
I would like to report that the issue I encountered appears to be a duplicate of Bug #114065 (https://bugs.mysql.com/bug.php?id=114065). I followed the steps described in the bug report, and I can confirm that the behavior is exactly as documented.

Please consider marking my report as a duplicate of Bug #114065.

Thank you for your attention to this matter.
[27 Nov 2024 16:18] MySQL Verification Team
Thank you, Mr. taha,

This bug report is a duplicate of the following one:

https://bugs.mysql.com/bug.php?id=114065
[27 Nov 2024 16:18] ahmed taha
using same code 8.0.32.1 i can catch the error

Attachment: 2.png (image/png, text), 26.89 KiB.

[27 Nov 2024 16:19] ahmed taha
using same code after upgrade mysql.net to 8.0.33

Attachment: 4.png (image/png, text), 135.30 KiB.

[27 Nov 2024 16:27] ahmed taha
I reported this bug last year, and it exhibits the same issue: https://bugs.mysql.com/bug.php?id=113501