Pool cannot detect idle connection disconnected by MySQL and will trigger `read ECONNRESET` on newly acquired connection
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 1query to test connections in the pool. - verifyConnection: boolean. If set
true, the pool will test a connection in the pool everyverifyConnectionIntervalseconds.
Read more here: Source link
