Repository navigation
fix(pg-cloudflare): do not emit an error for the read that end() cancels - #3806
Open
WolfieLeader wants to merge 1 commit into
Open
WolfieLeader wants to merge 1 commit into
WolfieLeader wants to merge 1 commit into
Conversation
Since brianc#3747, end() closes the Cloudflare socket while _listen() still waits on a read. workerd rejects that read with "This socket has been closed.", and pg re-emits it as a client 'error' after end() resolved. With no 'error' listener this is an unhandled rejection. Ignore a rejected read once end() has been called. Other read failures still emit 'error'.
WolfieLeader
marked this pull request as ready for review
October 6, 2026 14:55
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 #3805.
Since #3747,
CloudflareSocket.end()closes the socket while_listen()still waits on a read. workerd rejects that read with "This socket has been closed.", and pg re-emits it as a client'error'afterend()resolved. With no'error'listener, that is an unhandled rejection.This change ignores a rejected read once
end()has been called. Other read failures still emit'error'.Tests:
packages/pg-esm-test/pg-cloudflare.test.js. A fake reader keeps the read pending until the fakeclose()rejects it, as workerd does. Before: 36 pass, 1 fail. After: 37 pass.await client.end()after a query:pg_terminate_backend) still reaches the client as'error'.Not changed:
_listenOnce(), the SSL handshake read. In workerd,end()during the handshake did not reject that read.