node-postgres icon indicating copy to clipboard operation
node-postgres copied to clipboard

fix: double client.end() hang

Open cody-greene opened this issue 3 years ago • 4 comments

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 ✔

cody-greene avatar Mar 07 '22 00:03 cody-greene

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! ❤️

brianc avatar May 11 '22 18:05 brianc

Is anything else needed here?

cody-greene avatar May 24 '22 20:05 cody-greene

I tested this PR and it will also fix the issue I just reported in #2777. :+1:

MasterOdin avatar Jul 29 '22 01:07 MasterOdin

Can I do anything else to help get this merged, @brianc ?

cody-greene avatar Aug 16 '22 22:08 cody-greene

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?

mastermatt avatar Mar 06 '23 15:03 mastermatt

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 😄

brianc avatar Mar 06 '23 16:03 brianc

dreams-do-come-true-sm

cody-greene avatar Mar 07 '23 17:03 cody-greene

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

brianc avatar Mar 09 '23 05:03 brianc