Repository navigation
Workers: sql.end() closes once Terminate is written; test a request that never ends its client - #161
Merged
Merged
Conversation
okomarov
force-pushed
the
fix/workers-end-at-once
branch
from
October 19, 2026 23:54
e548caf to
f5c1415
Compare
okomarov
marked this pull request as ready for review
October 20, 2026 01:39
…nd() no longer waits a round trip Partially reverts 8e1827b: end() closes the socket as soon as Terminate is written again, as in 4.5.1. The rest of that commit stays: the handled close promise, the read loop closing on end of stream and the flagged matrix entry. 8e1827b made end() write Terminate and wait for PostgreSQL to close its side, so the read loop would see end of stream instead of a rejected read. That removed the unhandled-rejection log on compatibility dates before 2026-03-03, but every sql.end() then waited a full round trip for the server's close. On Cloudflare's network wall time per request rose by 122 to 135 ms against the Supabase pooler and Neon, with CPU unchanged. end() goes back to writing Terminate and closing once the write completes. Wall time is back to the latest release's (median 790 vs 791 ms on the Supabase pooler, 1008 vs 1008 ms on Neon over TLS). On dates before 2026-03-03 without unhandled_rejection_after_microtask_checkpoint each close logs one rejection that the read loop handles; queries are unaffected. The read loop still closes the socket when the server ends the stream, and the close promise stays handled. The workerd matrix marks the entries that log close rejections with WORKERD_CLOSE_REJECTIONS=logged and fails any close rejection elsewhere. A new no-end scenario returns from the request without ending the client and polls pg_stat_activity until its backend is gone. Locally and on the edge against Neon, the backend was gone by the first check (about 0.3 s and 1 s), and on old dates the teardown logs one close rejection. The Workers docs now show await sql.end(), say that ctx.waitUntil costs the same, and that leaving the client open also works. Addresses #1
okomarov
force-pushed
the
fix/workers-end-at-once
branch
from
October 20, 2026 10:53
f5c1415 to
ebc9ab2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft for CI. Reverts the end() wait from 8e1827b (one extra round trip per sql.end()), runs the workerd matrix with close rejections expected on dates before 2026-03-03 without the flag, and adds a no-end scenario that leaves a client open when the request finishes and checks how long its backend stays in pg_stat_activity, locally and on the edge against Neon.