Pool cannot detect idle connection disconnected by MySQL and will trigger `read ECONNRESET` on newly acquired connection
See original GitHub issueMySQL 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 everyverifyConnectionInterval
seconds.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:31 (19 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
All right, @sidorares, I added a PR. The PR includes two new configuration parameters:
enableKeepAlive
andkeepAliveInitialDelay
. The former defaults tofalse
, and the latter to0
. 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
@midnightcodr published as v2.1.0