Conversation
`Connection._send()` calls `stream.write(buffer)` with no callback, so `CloudflareSocket.write()` fell back to its no-op default callback and a rejected `WritableStreamDefaultWriter.write()` was discarded. The query then hung until the socket closed and the real failure surfaced only as "Connection terminated unexpectedly". Emit the rejection as an `error` event when no callback was supplied, matching what a `net.Socket` does, so `Connection` reports it. Writes that do pass a callback keep receiving the error there.
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.
Addresses the diagnosability half of #3757 (it does not claim to fix the hang itself; see below).
Summary
CloudflareSocket.write()declaredcallback: (error?: unknown) => void = () => {}.Connection._send()(packages/pg/lib/connection.js:175) callsthis.stream.write(buffer)with no callback, so that no-op default swallowed every rejection fromWritableStreamDefaultWriter.write().Connection terminated unexpectedly.callbackoptional and, when none was supplied,this.emit('error', err)— which is what anet.Socketdoes and what the rest ofpgis already wired for (Connection→Client._handleErrorEvent→_errorAllQueries). Writes that do pass a callback are unchanged and still get the error there.packages/pg-esm-test/pg-cloudflare.test.js: the emit path, and the callback path (so this can't regress thewrite(data, callback)support from fix: support callback as second argument toCloudflareSocket.write#3747).tsc -p packages/pg-cloudflare/tsconfig.json,prettier --checkandeslinton the two files: all clean.Decisions
emit('error')fires only in the branch that was previously a silent drop; every other path is byte-for-byte what it was.end()passes its own callback, so its handling is untouched (the existing close test still passes).Connection._send()(pass a callback there): larger blast radius across all transports for a defect in the Workers socket's own contract.writable = falseon failure:Client._handleErrorEventalready marks the client unusable once the error is emitted; kept to one change.Not run here: the full Node × PostgreSQL matrix (needs a live server; this touches only the Workers socket) and the
packages/pg/test/cloudflarevitest-pool-workers suite (needswrangler/workerd). #3718 is the only open PR touching this file; it changesend(), notwrite(), and is already superseded by #3735.AI assistance: the bug was traced and the fix and tests were drafted with AI tooling in my workflow, starting from @charmander's comment on #3757; the tests,
tsc, prettier and eslint were executed as pasted above. I'm responsible for the change and will handle review feedback.