MySql.Data.MySqlClient.MySqlException (0x80004005): Connect Timeout expired

See original GitHub issue

I have this problem several months and i can’t find the reason why this is happens. When i have high load on my website, connections to database from .net core increases to max value of my connection string (maximumpoolsize=100). And after that i receive multiple Connect timeouts. In meanwhile database is free, without locks, queries from another systems executes immediately (less than a second). So my connection pool is full, queries to database is not executed and database in this time works well. It seems that system can’t get connection from pool because old connections are hang. What can it be? Please help me.

MySql.Data.MySqlClient.MySqlException (0x80004005): Connect Timeout expired. ---> System.OperationCanceledException: The operation was canceled.
Apr 18 10:33:00 web portal[962]:    at System.Threading.CancellationToken.ThrowOperationCanceledException()
Apr 18 10:33:00 web portal[962]:    at System.Threading.SemaphoreSlim.<WaitUntilCountOrTimeoutAsync>d__32.MoveNext()
Apr 18 10:33:00 web portal[962]: --- End of stack trace from previous location where exception was thrown ---
Apr 18 10:33:00 web portal[962]:    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Apr 18 10:33:00 web portal[962]:    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
Apr 18 10:33:00 web portal[962]:    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Apr 18 10:33:00 web portal[962]:    at System.Threading.SemaphoreSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
Apr 18 10:33:00 web portal[962]:    at MySqlConnector.Core.ConnectionPool.<GetSessionAsync>d__0.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs:line 30
Apr 18 10:33:00 web portal[962]: --- End of stack trace from previous location where exception was thrown ---
Apr 18 10:33:00 web portal[962]:    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Apr 18 10:33:00 web portal[962]:    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
Apr 18 10:33:00 web portal[962]:    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Apr 18 10:33:00 web portal[962]:    at MySql.Data.MySqlClient.MySqlConnection.<CreateSessionAsync>d__77.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 355
Apr 18 10:33:00 web portal[962]:    at MySql.Data.MySqlClient.MySqlConnection.<CreateSessionAsync>d__77.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 370
Apr 18 10:33:00 web portal[962]: --- End of stack trace from previous location where exception was thrown ---
Apr 18 10:33:00 web portal[962]:    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
Apr 18 10:33:00 web portal[962]:    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Apr 18 10:33:00 web portal[962]:    at MySql.Data.MySqlClient.MySqlConnection.<OpenAsync>d__19.MoveNext() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 160

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
squalsoftcommented, Apr 18, 2018

I use 0.32 version from Pomelo.EntityFrameworkCore.MySql latest package. I will change to latest MySqlConnector 0.40.1 and give it a try. I have sometimes more than 100 simultaneous requests to my Nginx reverse proxy. I register Entity framework context as default dependency injection and inject it in my MVC Controller’s constructor. I don’t dispose it manually.

0reactions
panjungcommented, Apr 21, 2022

Although it is closed, I would like to mention that I solved the error by specifying Time out in the connection string. It was a little time-consuming on Google search to find out this: Add "default command timeout=120; " at the connection string.

See here: https://dev.to/solrevdev/mysqlexception-0x80004005-the-command-timeout-expired-before-the-operation-completed-khj

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySql.Data.MySqlClient.MySqlException: Timeout expired
Just add "default command timeout=xxx" into your connectString, this key's value is in seconds. I tried and it worked for me. Share.
Read more >
The Command Timeout expired before the operation ...
MySqlException (0x80004005): The Command Timeout expired before the operation completed. Tonight has all been about trying to get rid of some ...
Read more >
Connect Timeout expired. All pooled connections are in use.
Code: Error executing last component: MySqlConnector.MySqlException (0x80004005): Connect Timeout expired. All pooled connections are in use.
Read more >
MySql.Data.MySqlClient.MySqlException: Timeout expired
MySQL : MySql. Data. MySqlClient. MySqlException : Timeout expired [ Beautify Your Computer : https://www.hows.tech/p/recommended.html ] MySQL ...
Read more >
Connection Pool Failing Under Load
Data.MySqlClient.MySqlException (0x80004005): error connecting: Timeout expired. The timeout period elapsed prior to obtaining a connection ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found