Skip to content
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

Pool can't create new connections after connectionLimit is hit and the connections have been closed #764

Open
hallh opened this issue Apr 5, 2018 · 5 comments

Comments

@hallh
Copy link

hallh commented Apr 5, 2018

Possibly related to #683

I've run into an issue where using a Pool eventually blocks the client from creating new connections to MySQL. The issue is triggered when a connectionLimit is set and otherwise default settings.

From what I can tell, the issue happens when the connectionLimit has been reached, and all the original connections have since been closed. It doesn't matter whether it's the client or the server closing them.

The closed connections are being released, but not removed from the connection pool. If you try to get a new connection after the pool's last connection has been closed, the getConnection callback will wait in queue, effectively stalling forever until an already-closed connection becomes available.

There's a script here to trigger the issue.

Tested against:

The check here prevents closed connections from being removed from the pool. Which means the pool ends up being full of dead connections.

The connection._closing is being set here. This goes both for calling close()on the connection, and if MySQL aborts the connection.

By commenting out the return as shown in my fork, the connection will be cleaned up.

I don't mind doing a proper fix and PR, but need some more information on the intended behavior, and the reason for this if (connection._closing) check.

H

@sidorares
Copy link
Owner

thanks for taking time to debug this @hallh ! I'll try to review your comment some time this weekend

@azazael13
Copy link

I wonder if this is what is causing me to get errors. I have noticed the last few weeks that after my program has been running for awhile I will get the following error:
TypeError: Cannot read property 'query' of undefined.

I put in some debug code to see if my query was wrong, but my query is correct. I am now wondering if it meant the .query of conn.query (where conn is my connection from pool.getConnection).

@tian-yuan
Copy link

any progress?

@midnightcodr
Copy link

The fork from @hallh seems to be working for me to deal with the dead pool connection problem. But I wonder if there will be any side effects by applying that workaround. @sidorares it would be great if you can make some time to take a look, Thanks.

@midnightcodr
Copy link

midnightcodr commented Apr 28, 2019

Actually spoke too early, the fork from @hallh doesn't solve the dead pool connection problem. For the time being I am using a very simple workaround to query (select 1) my database server very couple of minutes hoping the connections won't become zombies. I'll see how it goes.

Edit 1: It turns out the cause of my connection pool depleted problem is because I forgot to call connection.release() after I initially call pool.getConnection()

Edit 2: Sorry I have to make one more edit, fixing the connecton.release() bug does not fix the zombie pool connections problem. So far the only workaround towards the dead pool problem is implementing a periodic querying the db with select 1, it's not ideal but at least it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants