Skip to content

fix(pg-cloudflare): safely end already-closed sockets#3718

Open
deepakganesh78 wants to merge 1 commit into
brianc:masterfrom
deepakganesh78:fix/issue3689-end-closed-socket
Open

fix(pg-cloudflare): safely end already-closed sockets#3718
deepakganesh78 wants to merge 1 commit into
brianc:masterfrom
deepakganesh78:fix/issue3689-end-closed-socket

Conversation

@deepakganesh78

Copy link
Copy Markdown

Summary

  • make CloudflareSocket.end() tolerate the underlying socket having already closed
  • preserve the normal close call for open sockets and always invoke the end callback
  • add pg-cloudflare unit-test support and regression coverage for the close-handler lifecycle

Root cause

_addClosedHandler() clears _cfSocket before emitting close. A later end()/destroy() still dereferenced _cfSocket after its write callback, causing a synchronous null.close() crash during client cleanup. The guarded close treats the already-closed state as complete without swallowing write errors or skipping the callback.

Related to #3695, which proposed the guard; this includes the regression test requested in that PR.

Tests

  • corepack yarn workspace pg-cloudflare test — 2 passing
  • corepack yarn build
  • corepack yarn eslint --cache "packages/**/*.{js,ts,tsx}"

Fixes #3689

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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: CloudflareSocket.end() throws null.close() when releasing a client whose socket already closed

1 participant