Skip to content

fix: support Cloudflare write callbacks - #3747

Open
zfaustk wants to merge 2 commits into
brianc:masterfrom
zfaustk:fix/cloudflare-socket-close-event
Open

fix: support Cloudflare write callbacks#3747
zfaustk wants to merge 2 commits into
brianc:masterfrom
zfaustk:fix/cloudflare-socket-close-event

Conversation

@zfaustk

@zfaustk zfaustk commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #3152.

Connection.end() calls write(data, callback). CloudflareSocket.write previously treated the callback as an encoding, so it never ran.

This adds explicit overloads for write(data, callback) and write(data, encoding, callback). The runtime dispatch stays in the existing write method; close and event behavior are unchanged.

Validation:

  • focused pg-cloudflare runtime test: 3 passed;
  • yarn build, yarn lint, Prettier, and git diff --check: passed;
  • type fixture: valid overloads compile, while write(data, callback, callback) fails with TS2345.

The full PostgreSQL/libpq integration suite and a real Cloudflare Worker E2E were not run locally.

Prepared with Codex assistance.

Emit the close event when the explicit close operation resolves and support the write(data, callback) overload used by Connection.end().

Fixes brianc#3152

@charmander charmander left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn’t look right. Maybe start with a PR for just the write overload and a corresponding test that exercises it, ideally typed correctly with an overload instead of accepting (data, callback, callback).

@zfaustk zfaustk changed the title fix: close Cloudflare sockets after failed connections fix: support Cloudflare write callbacks Aug 13, 2026
@zfaustk

zfaustk commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — I narrowed this to the write overload only.

The updated method now has explicit overloads for write(data, callback) and
write(data, encoding, callback). The focused test checks that the two-argument
callback runs exactly once, and a TypeScript fixture confirms that
write(data, callback, callback) is rejected. I removed the close-event and
closed-promise changes from this PR.

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.

Cloudflare Client.end() hangs if socket did not successfully connect

2 participants