Pool can't create new connections after connectionLimit is hit and the connections have been closed
See original GitHub issuePossibly 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:
MySQL:5.7
mysql2@1.5.3
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
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (1 by maintainers)
thanks for taking time to debug this @hallh ! I’ll try to review your comment some time this weekend
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 callpool.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 withselect 1
, it’s not ideal but at least it works.