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
I've been debugging this issue kibae/pg-logical-replication#20 and narrowed it down to the Client's end method not resolving (or calling the callback) under certain error conditions.
Minimal reproduction:
constclient=newClient(connOpts)awaitclient.connect()setImmediate(()=>{client.connection.stream.resetAndDestroy()// simulate a network outage or the db going offline e.g. ECONNRESETsetImmediate(async()=>{awaitclient.end()// <-- never resolves})})
Notably, by the time .end is called, the connection and its stream (a new.Socket instance) have already emitted their close and end events. However, .end relies on an end event from the connection to resolve, unless the connection never connected to begin with.
I believe the check to have .end resolve early should not only look at the _connecting flag, but should also check if the socket has been destroyed.
@fmmoret yes, it would fix this. I'm surprised I didn't come across that one when I was searching for existing issues. The cause is described differently, but it's the same underlaying issues of the stream having already emitted its 'close' event.
I've been debugging this issue kibae/pg-logical-replication#20 and narrowed it down to the Client's
end
method not resolving (or calling the callback) under certain error conditions.Minimal reproduction:
Notably, by the time
.end
is called, the connection and its stream (a new.Socket instance) have already emitted theirclose
andend
events. However,.end
relies on anend
event from the connection to resolve, unless the connection never connected to begin with.I believe the check to have
.end
resolve early should not only look at the_connecting
flag, but should also check if the socket has been destroyed.node-postgres/packages/pg/lib/client.js
Lines 605 to 606 in adbe86d
I believe these issues are related:
The text was updated successfully, but these errors were encountered: