-
-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: Can't add new command when connection is in closed state - with reproduction and work-around #1898
Comments
Some action items for me:
Instead of pool you could listen for 'error' event when server closes its side of connection ( Line 120 in 6bc6444
Also double check |
And thanks a lot for the repo and readme @abw - much appreciated! |
MySQL server uses TCP protocol to interact with its client. So, when client does not interact with the server long period of time(see WAIT_TIMEOUT config of MySQL, you can change it), the server can decide to disconnect their clients (see WAIT_TIMEOUT config of MySQL). But to be absolutely sure that MySQL does not disconnect it's client you need to enable keepAlive option on TCP connection from client side. But I do not recommend having long running connection in production. It would be better to close them automatically from time to time if they are in idle. So, this set of options for the mysql2 connection pool should help you to make 'balanced' communication in your specific case with your MySQL server:
The main idea behind this configuration is the And, |
@komanton I'm curious -- why set My understanding is Since your |
@abentpole You are right. It was my mistake about setting |
Any update on this issue? |
Hi, we investigated for a while this problem on our production systems, and we may have a fix which we thought we should share. The pool configuration contains the following options:
When creating the pool, we place a handler for errors on connections we create:
Hope it helps! |
@JustBeYou interesting, the pool already does this with the exception that it only removes connection from the pool in case its "fatal" error ( e.g when connection is healthy and it's just for exapmle sql syntax error we can keep it ) We probably need to check all possible scenarios when connection is marked as "closed state" agains when it's actually removed from the pool, might be some missing cases |
Any update on this? Or this is the final solution guys |
use connection pool |
This is a follow-on to #939
I've reproduced the problem with a self-contained repository/docker container.
https://github.com/abw/mysql-disconnect
The work-around is described in the README. Thanks to @irepela and @MaksemM for providing the work-around.
In short, you should run queries through the pool which will detect timed out connections and replace them.
I'm not sure that there's any action required or anything that can be done to easily fix the problem in node-mysql2 but I wanted to post this here for visibility in case anyone else is having the same problem. The above repository hopefully makes it easy to reproduce and investigate the problem.
The text was updated successfully, but these errors were encountered: