question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
sidorarescommented, Apr 6, 2018

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

0reactions
midnightcodrcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When a MySQL pool connection is released, should the ...
Connections are "lent" to client code that needs to access the database, and when the client code is done, the connection is returned...
Read more >
Resolve "Too Many Connections" error when ... - AWS
I am trying to connect to my Amazon Aurora MySQL DB instance, and I am getting the "Too Many Connections" error.
Read more >
Pooling Connections in Node.js & MySQL | by Ritu Raj - Medium
In connection pooling, after a connection is created, it is placed in the pool and it is used again so that a new...
Read more >
.NET Framework Connection Pool Limits and the new Azure ...
After the maximum number of connections is reached, HTTP requests will be ... Azure SDKs are set up to retry intermittent connection issues ......
Read more >
Connection management (Guide) - Prisma
might allow more processes to connect but; ✘ significantly affects database performance, and can result in the database being shut down due to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found