pool.end() does not return a proper promise
riimeik opened this issue · comments
I encountered an issue in my software wherein connections would be left open, thus reaching the PostgreSQL connection limit for that user after a few runs.
My code basically did this:
- open a VPN connection;
- connect to a database, fetch data;
- terminate the pool (wait for the returned promise);
- close the VPN connection.
As it turned out, pg-pool was unable to properly terminate idle connections, because the VPN tunnel was closed before necessary signals could be sent. I could solve the issue by waiting an extra second between points 3) and 4), so I suspect the issue lies on these lines: 91 and 135. Namely, client.end() returns a promise that resolves only once it receives the 'end' signal, but this promise is not forwarded to _pulseQueue(), which reports the pool as properly closed as soon as it simply requests the closing of all idle connections.