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 cannot detect idle connection disconnected by MySQL and will trigger `read ECONNRESET` on newly acquired connection

See original GitHub issue

MySQL will disconnect idle connections after certain time frame.

This time frame is determined by MySQL variable wait_timeout.

It seems mysql2’s pool implementation cannot detect this type of disconnection (ping is not sufficient).

And when it happens, any queries sent through the acquired connection will trigger a read ECONNRESET error.

At this moment, I have to send a SELECT 1 query to test the acquired connection before use.

And previous code that calls pool.query directly will have to be re-written.

Can Mysql2 provides two extra pool creation options:

  • verifyConnectionInterval: number of seconds before pool should send SELECT 1 query to test connections in the pool.
  • verifyConnection: boolean. If set true, the pool will test a connection in the pool every verifyConnectionInterval seconds.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:31 (19 by maintainers)

github_iconTop GitHub Comments

3reactions
benbottocommented, Dec 13, 2019

All right, @sidorares, I added a PR. The PR includes two new configuration parameters: enableKeepAlive and keepAliveInitialDelay. The former defaults to false, and the latter to 0. I opted to keep keep-alive off by default to avoid unexpected side effects in existing code.

https://github.com/sidorares/node-mysql2/pull/1081

1reaction
sidorarescommented, Dec 24, 2019

@midnightcodr published as v2.1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL giving "read ECONNRESET" error after idle time on ...
It is either a bug in the node-MySQL connection pool implementation, o else you haven't configured it properly to detect failures. Share.
Read more >
MySQL Bugs: #40036: Connector "lost" pooled connections.
something new? The connector may need to check if connection losted open, then return to the pool, or set a "timeout" for connection,...
Read more >
node-mssql | Microsoft SQL Server client for Node.js
Once the action is complete, connection is released back to the pool. Connection health check is built-in so once the dead connection is...
Read more >
mysql - npm
It is written in JavaScript, does not require compiling, ... The pool will create a new connection the next time one is needed....
Read more >
Node.js Express: JWT example | Token Based Authentication ...
First five parameters are for MySQL connection. pool is optional, it will be used for Sequelize connection pool configuration: max : maximum ...
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