fix: double client.end() hang
fixes https://github.com/brianc/node-postgres/issues/2716
client.end() will resolve early if the connection is already dead, rather than waiting for an "end" event that will never arrive. This also makes client.end() resolve only when the underlying socket is fully closed, both the readable part ("end" event) & writable part ("close" event).
https://nodejs.org/docs/latest-v16.x/api/net.html#event-end
Emitted when the other end of the socket signals the end of transmission, thus ending the readable side of the socket.
https://nodejs.org/docs/latest-v16.x/api/net.html#event-close_1
Emitted once the socket is fully closed.
test before change:
2716-tests.js
client.end() should resolve if already ended
Error: test: client.end() should resolve if already ended did not complete withint 5000ms
at Timeout._onTimeout (/home/cody/repos/node-postgres/packages/pg/test/suite.js:52:19)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)
test after change:
2716-tests.js
client.end() should resolve if already ended ✔
Hey sorry for the headache here but CI was broken. I fixed it yesterday...would you be able to rebase onto master? Then the tests should pass and we can merge this up and get a release out! Thank you so much for contributing! ❤️
Is anything else needed here?
I tested this PR and it will also fix the issue I just reported in #2777. :+1:
Can I do anything else to help get this merged, @brianc ?
This will also fix https://github.com/brianc/node-postgres/issues/2923. @brianc as today is the one year anniversary for this PR, could we get you to take a fresh look at the change?
as today is the one year anniversary for this PR, could we get you to take a fresh look at the change?
haha yes I'll get this released today 😄

haha yeah sorry it took so long...sometimes things get buried for me in my inbox and go bye bye - appreciate it deeply though! ❤️