I reached out to the node-mysql folks on their Github page and got some firm answers.
-
MySQL does indeed prune idle connections. There’s a MySQL variable “wait_timeout” that sets the number of second before timeout and the default is 8 hours. We can set the default to be much larger than that. Use
show variables like 'wait_timeout';
to view your timeout setting andset wait_timeout=28800;
to change it. -
According to this issue, node-mysql doesn’t prune pool connections after these sorts of disconnections. The module developers recommended using a heartbeat to keep the connection alive such as calling
SELECT 1;
on an interval. They also recommended using the node-pool module and its idleTimeoutMillis option to automatically prune idle connections.