-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling .end
on a client (or pool) does not wait for connections to close
#3287
Comments
Yes, please add a callback to The issue manifested itself like this for me: I use this package to verify DB writes in E2E tests, and Jest had this error:
Running Jest with
My code for reference
|
@opyate the |
Ah, of course, I missed Here's my solution for anyone else landing here.File setupFilesAfterEnv.ts:
And my helper becomes:
|
Hi there, it seems that there is a bug around
client.end
/pool.end
in that when awaited (or using callbacks) the promise can resolve before the underlying connection / stream has disconnected.Digging through the code a bit, it seems like the issue is in this bit of code:
node-postgres/packages/pg/lib/connection.js
Lines 189 to 199 in 54eb0fa
I think here we should hook into the callback from the sockets end event: https://nodejs.org/api/net.html#socketenddata-encoding-callback and ensure that the original promise does not resolve (or callback fire) before observing this.
The text was updated successfully, but these errors were encountered: