sidorares / sidorares/node-mysql2
Pool can't create new connections after connectionLimit is hit and the connections have been closed
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 4.4k
- Forks
- 680
- Avg merge
- 9h 7m
- Merged PRs (30d)
- 59
Description
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:
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/connection.js around lines 94 and 793, then run the linked reproduction script to observe pool behavior after connections close. Trace why closed connections remain in the pool and confirm that getConnection can obtain a usable replacement without stalling; done means dead connections are cleaned up and the reported scenario no longer blocks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, node.js
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100