C
C#4mo ago
SoFt

Weirdest problem - catch doesnt work

c#
try
{
using (var connection = new MySqlConnection("Server=x;Port=3306;Database=x;Uid=x;Pwd=x;Pooling=true"))
{
await connection.OpenAsync();
}
}
catch(Exception ex)
{
var q2 = "";
}
c#
try
{
using (var connection = new MySqlConnection("Server=x;Port=3306;Database=x;Uid=x;Pwd=x;Pooling=true"))
{
await connection.OpenAsync();
}
}
catch(Exception ex)
{
var q2 = "";
}
x is actually my server's info If my server is running, this works ok. But if I reboot my server, this code throws unhandled exception! Basically catch doesnt work!
```System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs:line 831
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 683
at System.Threading.TimerQueue.FireNextTimers() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 331
at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 913
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.NonBrowser.cs:line 102

Inner Exception 1:
MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Inner Exception 2:
TimeoutException: The operation has timed out.
```System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs:line 831
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 683
at System.Threading.TimerQueue.FireNextTimers() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 331
at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 913
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.NonBrowser.cs:line 102

Inner Exception 1:
MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Inner Exception 2:
TimeoutException: The operation has timed out.
``` How is this possible?
10 Replies
webczat
webczat4mo ago
might be that exception is being thrown from some different context than you expect, like some other thread, not in the async flow?
SoFt
SoFt4mo ago
I just have this snip runnig on the main thread, right where the form loads. No other code
webczat
webczat4mo ago
so doesn't correctly propagate but OpenAsync calls into a db provider which can do whatever. the responsible code is the provider.
SoFt
SoFt4mo ago
Are you saying there is something wrong with the mysql library? Or that I need to handle it some other way
Pobiega
Pobiega4mo ago
afaik there are plenty of things wrong with the mysql library, especially the ones not from Pomelo
webczat
webczat4mo ago
there might be something wrong with the mysql library. AggregateException is kinda rare especially in async/await, it is usually seen when doing direct Task manipulation and like... not sure
Jimmacle
Jimmacle4mo ago
do you have the full exception and stack trace? where does it point to?
SoFt
SoFt4mo ago
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs:line 831
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 683
at System.Threading.TimerQueue.FireNextTimers() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 331
at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 913
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.NonBrowser.cs:line 102

Inner Exception 1:
MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Inner Exception 2:
TimeoutException: The operation has timed out.
System.AggregateException
HResult=0x80131500
Message=One or more errors occurred. (Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.)
Source=System.Private.CoreLib
StackTrace:
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs:line 831
at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 683
at System.Threading.TimerQueue.FireNextTimers() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 331
at System.Threading.ThreadPoolWorkQueue.Dispatch() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs:line 913
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.WorkerThread.NonBrowser.cs:line 102

Inner Exception 1:
MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Inner Exception 2:
TimeoutException: The operation has timed out.
webczat
webczat4mo ago
i don't really know what can cause that. unhandled exception which is thrown from a cancellation callback?
SoFt
SoFt4mo ago
I have switched to MySqlConnector and now catch actually works... Thanks for the help
Want results from more Discord servers?
Add your server