Skip to content

fix(pg-cloudflare): emit write errors that have no callback - #3784

Open
askalf wants to merge 1 commit into
brianc:masterfrom
sprayberry-code:fix/cf-socket-surface-write-errors
Open

askalf wants to merge 1 commit into
brianc:masterfrom
sprayberry-code:fix/cf-socket-surface-write-errors

Conversation

@askalf

@askalf askalf commented Sep 14, 2026 •

Copy link
Copy Markdown

Covers the diagnosability half of #3757. It does not claim to fix the hang itself.

CloudflareSocket.write() defaulted its callback to a no-op. Connection._send() writes without a callback, so a rejected WritableStreamDefaultWriter.write() was swallowed and the query sat unsettled until the socket closed with the generic Connection terminated unexpectedly.

The callback is now optional. When none is supplied the error is emitted on the socket, which is what net.Socket does and what Client._handleErrorEvent already handles. Writes that pass a callback are unchanged.

Tests: one new test fails on main and passes here, plus one control pinning the callback path from #3747. tsc, prettier and eslint are clean.

AI tooling helped trace and draft this; I ran the tests and own the change.

`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.
@askalf

askalf commented Sep 29, 2026

Copy link
Copy Markdown
Author

@charmander friendly ping on this one when you have a moment. It's the write-error half of #3757 you mentioned, CI is green and it still merges cleanly. Happy to adjust anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant