Skip to content

fix(pg-cloudflare): emit close after the socket's closed promise rejects - #3824

Open
Saadanjum0 wants to merge 1 commit into
brianc:masterfrom
Saadanjum0:fix/pg-cloudflare-closed-rejection
Open

Saadanjum0 wants to merge 1 commit into
brianc:masterfrom
Saadanjum0:fix/pg-cloudflare-closed-rejection

Conversation

@Saadanjum0

Copy link
Copy Markdown

Fixes #3822

When the Cloudflare socket's closed promise rejects, CloudflareSocket emits error but never close. Connection only emits end on the stream's close, so client.end() on that connection never resolves. workerd can also reject closed with undefined, which then reaches reportStreamError in pg/lib/connection.js and throws on error.code.

The fix makes the rejection path in _addClosedHandler() behave like net.Socket: emit error (wrapping an undefined rejection in an Error), then emit close if that socket is still the current one. The _cfSocket === socket check is the same one the resolve path and end() already use, so close is still emitted at most once.

Testing: added a case to pg-esm-test/pg-cloudflare.test.js that rejects closed with undefined and expects an Error followed by close. It fails on master (no close within the timeout) and passes with this change. The rest of the pg-cloudflare tests pass, and eslint and prettier are clean on the touched files.

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.

pg-cloudflare: no 'close' when workerd rejects the socket's closed promise, so client.end() never resolves

1 participant