fix: settle COPY writable final callback on server error - #1183
Open
GiHoon1123 wants to merge 1 commit into
Open
fix: settle COPY writable final callback on server error#1183GiHoon1123 wants to merge 1 commit into
GiHoon1123 wants to merge 1 commit into
Conversation
Failed COPY FROM STDIN never invoked the stashed Writable/Duplex final() callback when the server rejected the data with ErrorResponse instead of CommandComplete. This left the writable hanging forever, which meant stream.pipeline() (and any await on stream finish) never settled. Inside sql.begin(), the transaction callback never returned, so ROLLBACK was never sent and the connection leaked permanently as 'idle in transaction (aborted)'. errored() already cleaned up stream/query/initial on this path but never invoked the pending final callback. Calling final(err) settles the stream with the real PostgresError, so pipeline() rejects, sql.begin() can roll back, and the connection returns to the pool. Fixes porsager#1173
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1173
Problem
When
COPY ... FROM STDINfails after.end()has sentCopyDone, thepending writable final callback is never called.
On the success path,
CommandCompletecalls the storedfinalcallback.On the failure path, Postgres sends
ErrorResponseandReadyForQueryinstead, which goes through
errored(). That path cleaned up the currentstream/query state, but did not settle the pending
finalcallback.That leaves
stream.pipeline()or any code awaiting the writable stuckforever. Inside
sql.begin(), the transaction callback never returns, soROLLBACKis not sent and the connection is left idle in an abortedtransaction.
Fix
Call the pending
finalcallback with the Postgres error fromerrored():This makes the writable reject with the server error, allowing callers to
handle it normally and allowing
sql.begin()to roll back.The existing mid-write error path is unchanged: if the error arrives before
.end()storesfinal,stream.destroy(err)still handles it.Testing
COPY FROM STDINafter.end()idle in transaction (aborted)