coopernurse / node-pool

Generic resource pooling for node.js
2.37k stars 258 forks source link

Is there a connection keep alive hook? #267

Open sarus opened 5 years ago

sarus commented 5 years ago

Hello,

I wanted to see if there was a built-in way or best practice for implementing a keep alive function to ensure that connections in the connection pool do not timeout after being idle for X number of seconds. For example, if I have a pool with connections that will disconnect if left idle for 600 seconds, then I would be looking for a way to guarantee that a keep alive function is executed at least once per connection every 600 seconds (ideally taking into account the last time the connection was acquired so that the keepalive only runs if a connection has not been acquired within the idle window).

This capability is useful where keeping a long running connection alive is a cheap operation but destroying and creating a new connection from scratch is expensive.

Thank you!