Closed rmoestl closed 6 years ago
I wonder if pool is closing its connections when node.js is exiting for whatever reason.
The pool doesn't hook in to any node lifecycle events by default so it does nothing if node exits for whatever reason. Your connections to postgres are dropped as a by-product of the process exiting.
If you want to end the pool calling pool.end
yourself is the way to go; however, it's not a big deal if your process exits and the connections drop - postgres is fine with this. Using pool.end
is more for when you need a disconnect in your app - either for tests to end properly or to make sure your pool is closed before opening a new one or something similar.
Thanks for clarifying!
This is a question rather than a issue.
I wonder if
pool
is closing its connections when node.js is exiting for whatever reason. There ispool.end()
but that's asynchronous which means that you can't call it in process.on('exit', callback) since node will terminate immediately afterwards without doing any further work in the event loop.Calling
pool.end()
in thebeforeExit
event, that allows for asynchronous code, isn't a complete solution either, sincebeforeExit
isn't called in some situations.One could listen for the uncaughtException event, but in the respective callback you should