-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unref setTimeout use in pg-pool #2078
Comments
I think (1) is cleared by Have you seen a bug (in a minimal script) where pool timeouts are keeping the process running after ending the pool? |
It occurred to me that this could be useful. The http.Agent class in Node.js unrefs sockets that are not currently handling an HTTP request, so they stick around in memory, but they don't stop the process from exiting if they're not actively being used. So the question is: can pg-pool unref sockets or timeouts if they're not currently in use? Can I create a pool that will let the process end without calling pool.end() first? |
@fluggo Yep, the pool could do that. |
Based on the suggestion from #2078. This adds ref/unref methods to the Connection and Client classes and then uses them to allow the process to exit if all of the connections in the pool are idle. This behavior is controlled by the allowExitOnIdle flag to the Pool constructor; it defaults to the old behavior.
In at least two cases,
pg-pool
creates a referenced timeout:node-postgres/packages/pg-pool/index.js
Lines 292 to 295 in 3f6760c
node-postgres/packages/pg-pool/index.js
Lines 171 to 177 in 3f6760c
These timeouts are currently keeping the process from dying naturally.
Use
setTimeout().unref()
to prevent this.Unless I am overlooking a need to keep the pool awake?
The text was updated successfully, but these errors were encountered: