Skip to content

fix(workerd): end connections without an unhandled rejection on older compatibility dates - #160

Merged
okomarov merged 1 commit into
mainfrom
cf-close-rejections
Oct 19, 2026
Merged

okomarov merged 1 commit into
mainfrom
cf-close-rejections

Conversation

@okomarov

Copy link
Copy Markdown

Work on #1. First commit finds which compatibility flag removes the close-time rejections; the polyfill change follows once the counts are in.

Refs #1

@okomarov
okomarov force-pushed the cf-close-rejections branch from 8e70d13 to 064e57e Compare October 19, 2026 22:46
@okomarov okomarov changed the title fix(workerd): stop close-time unhandled rejections on older compatibility dates fix(workerd): end connections without an unhandled rejection on older compatibility dates Oct 19, 2026
… compatibility dates

The cloudflare:sockets polyfill closed the socket as soon as Terminate was
written. close() closes both sides, so the read that is always pending
rejected. The read loop's catch handled it, but before workerd's
unhandled_rejection_after_microtask_checkpoint flag (cloudflare/workerd#6020,
on by default from compatibility date 2026-03-03) workerd reported the
rejection as unhandled first. In the local workerd matrix, turning only that
flag on at 2025-01-01 took close-time rejections from 27 to 0 across 15
scenarios, and turning it off at 2026-10-12 brought 26 back.

end() with Terminate now writes it and leaves the socket open, as
socket.end() does in Node: PostgreSQL closes its side, the read loop sees end
of stream and the socket closes once, with no rejected read. A close without
data still closes at once, with its promise handled, and the connection's
close timer still bounds a server that never closes. At 2025-01-01 and
2025-09-15 without the flag, graceful scenarios (end-plain, timers, copy-out,
subscribe, ssl-prefer-declined, end-tls) went from 15 rejections to 0.

Forced closes (connect-timeout, end-timeout, end-while-connecting) still
report one per close on those dates. Cancelling the pending read first
changed nothing and hung the Node-level core-plain case, so those stay
documented: move to 2026-03-03 or set the flag.

The workerd runner now fails any other scenario that logs a close-time
rejection, takes extra compatibility flags from WORKERD_COMPAT_FLAGS and
keys expected failures per matrix entry, since tls-untrusted-ca follows the
same flag. The matrix adds 2025-01-01 with the flag.

Closes #1
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