-
-
Notifications
You must be signed in to change notification settings - Fork 595
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 not releasing connections if maxIdle is not set #2493
Comments
Hi @danj1980, 🙋🏻♂️ It's not directly related, but can you check if this PR affects this behavior in some way? Also, this workaround: Possibly related |
It seems I've found the issue. If maxIdle is not set on the pool, _removeIdleTimeoutConnections is never executed, and therefore there is never any cleanup of released connections. Line 30 in b87ee44
If maxIdle is set, the released connections get cleaned up. |
Side note, if I manually kill a connection on MySQL server, execution continues in the pool until the connections fill back up again. |
I dont think that's the same issue, as the CPU usage is 0% when the connections run out.
This workaround looks similar to my test where I'm getting a connection, querying it, and then immediately releasing it. |
@danj1980, can you provide a minimal repro for this issue? According to the documentation, that should be the default behavior for {
connectionLimit: 10,
maxIdle: 10, // max idle connections, the default value is the same as `connectionLimit`
} |
I'm sorry. Let me clarify my fix.... In order to get it to cleanup old released connections, I had to set maxIdle < connectionLimit. If maxIdle is default (eg. maxIdle => connectionLimit), no cleanup of old released connections occurs as shown below. Line 30 in b87ee44
Unfortunately, I cannot create a demo repo. I've never posted code to github and wouldn't know where to start. |
There is also a factor that I've not quite figured out. Sometimes connections are reused. Sometimes they aren't. I would guess that the connection's idleTimeout is reached, that connection is marked as "old" and pending releasing, and therefore a new connection is created, but the old ones aren't cleaned up. |
So, currently there are these tests for idle connections:
But unfortunately, I can't reproduce this behavior to implement a specific test case for it 😕 |
In that test, |
Thanks, @danj1980 🚀 I'll show how I perform the tests locally using Docker, but you can also see the Contributing.md. Choose a directory
mkdir -p Desktop/sidorares
cd Desktop/sidorares Clone this repositorygit clone https://github.com/sidorares/node-mysql2.git Create a Docker Compose file
version: '3.9'
services:
db:
image: mysql:latest
restart: always
environment:
MYSQL_DATABASE: 'test'
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
ports:
- '127.0.0.1:3306:3306'
healthcheck:
test: ['CMD', 'mysqladmin', 'ping', '-h', 'localhost', '-u', 'root']
interval: 10s
timeout: 5s
retries: 5
node-mysql2:
image: node:lts-alpine
working_dir: /usr/app
volumes:
- ./node-mysql2:/usr/app
command: npm run test
environment:
MYSQL_HOST: db
FILTER: test-pool-release-idle-connection
depends_on:
db:
condition: service_healthy Then, edit the Finally, test it:
As it should be a case not covered, it's expected to exit with |
Usually, this way (above) is when we want to submit a PR (which are always welcome). But if you prefer to show just a minimal code to reproduce this error, we can try that too 🙋🏻♂️ |
This happens to me too. I'm having exactly the same problem. Here is my codes; db.js
users-repo.js
SomeFunc output before getAllUsers function
SomeFunc output after getAllUsers function
SomeFunc output after some time has passed
|
Any solution? |
All of my queries include dbConnection.release(), however the connections do not get released and once connectionLimit is reached, the execution pauses waiting for an available connection.
I've re-worked my code so that every pool.getConnection() has a dbConnection.release() right next to it, to make absolutely certain that I'm not accidentally leaving any connections unreleased.
However, this did not help, and it seems that there is a bug in the releasing of pool connections.
I store my pool in a static variable with a class called Global.
Runs once on startup
Example usage
The text was updated successfully, but these errors were encountered: