Bug #114257 Error Handling Issue with MySql.EntityFrameworkCore
Submitted: 7 Mar 2024 8:48 Modified: 19 May 4:08
Reporter: WEI CHI WANG Email Updates:
Status: Analyzing Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:9.0.3 OS:Windows (11)
Assigned to: MySQL Verification Team CPU Architecture:x86 (i5-12500)

[7 Mar 2024 8:48] WEI CHI WANG
Description:
When attempting to execute asynchronous methods like CanConnectAsync(), ToListAsync(), etc., with MySQL.EntityFrameworkCore and encountering a blocked connection due to firewall restrictions or incorrect host entry, the application experiences uncatchable exceptions, leading to immediate application crashes. Synchronous methods, however, function correctly under the same circumstances.

How to repeat:
1. Set up MySql.EntityFrameworkCore in an application.
2. Intentionally block the connection using a firewall or provide incorrect host information.
3. Invoke asynchronous methods such as CanConnectAsync(), ToListAsync(), etc.
4. Observe the application crash without the ability to catch the exception.

Suggested fix:
The expected behavior should involve the proper handling of exceptions when the connection is blocked by a firewall or an incorrect host address is provided. Instead of crashing the application, it should gracefully handle the exception, allowing for proper error logging and application stability.
[7 Mar 2024 9:22] WEI CHI WANG
Occurred in ASP.NET Core MVC controller action
[7 Mar 2024 11:56] MySQL Verification Team
Hello!

Thank you for the bug report.
Could you please provide repeatable test case (sample project etc. - please make it as private if you prefer) to repeat this issue at our end?

Regards,
Ashwini Patil
[8 Mar 2024 1:22] WEI CHI WANG
Hello Ashwini Patil,

Thank you for your prompt response and for reviewing the bug report. I've provided the sample project and the code snippet where the uncaught exception occurs below:

Sample project: https://gitlab.com/wei-chi.wang/mysql.entityframeworkcore.bug.reappear

Code snippet where the uncaught exception occurs: https://gitlab.com/wei-chi.wang/mysql.entityframeworkcore.bug.reappear/-/blame/main/Contro...

Please let me know if you need any further information or assistance.

Best regards,
WEI CHI WANG
[16 May 10:24] MySQL Verification Team
Hello!

Thank you for the details.
Could you please upgrade to latest version? Report us back if you are still facing any issues with all the details like version etc.

Regards,
Ashwini Patil
[19 May 1:33] WEI CHI WANG
Hello Ashwini,

Thank you for your response.

I have already upgraded my application to .NET 8.0 and updated the package to:

<PackageReference Include="MySql.EntityFrameworkCore" Version="9.0.3" />

However, the issue still persists. When the connection is blocked (e.g., by firewall or incorrect host), calling asynchronous methods like CanConnectAsync() or ToListAsync() still results in uncatchable exceptions, causing the application to crash immediately. Synchronous methods do not have this issue under the same conditions.

Please advise if there are any additional steps or configurations that could help resolve this behavior.

Best regards,
WEI CHI WANG