Repository navigation
perf: close a connection without building an error nothing reads - #169
Merged
Merged
Conversation
Every graceful close built a CONNECTION_CLOSED error with a stack trace:
enterClosed() took it as its default after sql.end() (the Closing phase's
clean socket close, its timeout and terminate) and on terminate while
idle. Only a COPY stream, a final callback, the current or a sent query,
an acquisition or a reserved owner receives it, and a normal sql.end()
has none of them. On Workers a client is created and ended per request,
and the error was 1.4-2% of samples on connect, select 1, end under the
local workerd profiler.
enterClosed() now builds it only when one of those exists. The pool's
closedWhileEnding() builds its own when a reconnect closes gracefully
with queries still queued, as leaseError() does for leases.
The closing-no-error startup case counts Errors.connection calls across
sql.end() and sql.end({ timeout: 0 }); it saw two on main and none now.
Closes #167
okomarov
force-pushed
the
perf/close-without-error
branch
from
October 20, 2026 12:57
0f283c3 to
9ff3b83
Compare
This was referenced Oct 20, 2026
Closed
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.
A graceful close builds its CONNECTION_CLOSED error only when a COPY stream, a final callback, the current or a sent query, an acquisition or a reserved owner will receive it. The pool builds its own in closedWhileEnding() when a reconnect closes gracefully with queries still queued. The new closing-no-error startup case counts Errors.connection calls across sql.end() and sql.end({ timeout: 0 }): two on main, none here.
Closes #167
Measurements (CPU per request in ms, connect,
select 1, end; release → this branch)Local workerd profile, 200 rounds (https://github.com/steadybrew/postgresjs/actions/runs/39428234607):
errors.jsfalls from 1.3% (fetch_types off) and 1.0% (on) of samples to 0.0%; medians unchanged at 2.53 and 3.46, p = 0.078 and 0.49.Node.js 24, same run: median 1.91 → 1.85 with fetch_types off (p = 0.00062), 2.39 → 2.34 with it on (p = 0.019).
Edge
cpujob, 150 rounds (https://github.com/steadybrew/postgresjs/actions/runs/39425601839): medians and p95 identical in all three groups (Supabase 8/12 and 12/17, Neon 9/13); gate passes (p = 0.38 and 0.48). p99 17 → 29 (Supabase, fetch_types off) and 15 → 25 (Neon) rest on the top one or two of about 128 requests.Edge A/B against main, 150 rounds, Supabase pooler, fetch_types false (https://github.com/steadybrew/postgresjs/actions/runs/39437582660): median 6 and 6, p95 10 → 8, p99 18 → 9, max 27 → 18; costs less, p = 0.12, so no detectable change on the edge. The A/A run (https://github.com/steadybrew/postgresjs/actions/runs/39437577733) shows warm-isolate spikes of 26 ms on unchanged code.