Closing postgres client properly
This fixes a couple issues: * Multiple decrements of `pendingQueries` for the same query. Since we have a `complete` handler in addition to `success` and `error`, `endQuery` gets called twice if it's a success or an error. This means that we will end up with `pendingQueries < 0` so the disconnect condition is never satisfied. * We were hooking into pg's `drain` event during the disconnect step, this is already too late since most of the time, the drain event is already fired. We need to hook into the `drain` event on client creation. Sadly, we cannot close the connection on the `drain` event as it will break with the error, `Error: Stream unexpectedly ended during query execution`
Showing
with
11 additions
and
5 deletions
-
Please register or sign in to post a comment