You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const client = new pg.Client()
await client.connect()
await client.end() // ok
await client.end() // uh-oh! This never resolves!
Ideally we should just not try to end the client twice in a row. But in using other packages, that wrap node-postgres, I've encountered a situation where I need to access the pg Client instance and end() it, before returning it to some wrapper class which may also try to end() it at some point. Arguably this wrapper class should be smarter and avoid calling end() if it sees the "end" event. But just the same client.end() shouldn't hang either.
return new this._Promise((resolve) => {
this.connection.once('end', resolve)
})
When the client has already ended, we just wait for a "end" event which never arrives. I imagine the fix here is to check for a private field like this._ended (as a compliment to this._ending) and return/resolve early.
The text was updated successfully, but these errors were encountered:
* fix: double client.end() hang
fixes#2716
`client.end()` will resolve early if the connection is already dead,
rather than waiting for an "end" event that will never arrive.
* fix: client.end() resolves when socket is fully closed
thijs
pushed a commit
to thijs/node-postgres
that referenced
this issue
Aug 1, 2023
* fix: double client.end() hang
fixesbrianc#2716
`client.end()` will resolve early if the connection is already dead,
rather than waiting for an "end" event that will never arrive.
* fix: client.end() resolves when socket is fully closed
Ideally we should just not try to end the client twice in a row. But in using other packages, that wrap node-postgres, I've encountered a situation where I need to access the pg Client instance and
end()
it, before returning it to some wrapper class which may also try toend()
it at some point. Arguably this wrapper class should be smarter and avoid callingend()
if it sees the "end" event. But just the sameclient.end()
shouldn't hang either.After a quick look at the source:
When the client has already ended, we just wait for a "end" event which never arrives. I imagine the fix here is to check for a private field like
this._ended
(as a compliment tothis._ending
) and return/resolve early.The text was updated successfully, but these errors were encountered: