You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FIXED in 4.6.0] Every graceful close builds a CONNECTION_CLOSED error that nothing reads #167
Every graceful close builds a CONNECTION_CLOSED error, with a stack trace, that nothing reads.
enterClosed(err = Errors.connection('CONNECTION_CLOSED', options, socket), reported = err) in src/connection.js takes its default when a connection closes normally: from the Closing phase after sql.end() (socketClose without an error, closeTimeout, terminate) and from terminate while idle. The error only matters when something is still waiting on the connection: a COPY stream, a final callback, the current or a sent query, an acquisition, a reserved owner, or queries the pool rejects in closedWhileEnding. On a normal sql.end() none of these exist.
On Cloudflare Workers a client is created and ended per request, so every request pays for it. On connect, select 1, end under the local workerd profiler, Errors.connection is 1.4-2% of samples.
Proposal
Build the error only when one of those receivers exists, and leave the close itself unchanged. Errors that do reach a caller keep their code, message, address and stack.
Measure
Edge cpu job at 150 rounds against npm latest, judged by median and p95 with the rank test. Expected to be below the resolution of cpuTimeMs (whole ms) on its own.
Same pattern, not in this issue: per-client parseOptions and mergeUserTypes (about 3% together on the same profile).
Landed on main in 9ff3b83 (PR #169); ships in the next release.
A graceful close now 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 before, none now. A first version also replaced a null error thrown by a socket factory; the Deno job caught it, and the check now applies only to undefined.
Measured CPU per request (connect, select 1, end):
Local workerd profiler, 200 rounds (run 39428234607): errors.js falls from 1.3% (fetch_types off) and 1.0% (on) of samples to 0.0%; per-request medians unchanged at 2.53 and 3.46 ms (p = 0.078 and 0.49).
Node.js 24, same run: median 1.91 → 1.85 ms with fetch_types off (p = 0.00062), 2.39 → 2.34 ms on (p = 0.019).
Edge, A/B against main, 150 rounds, Supabase pooler (run 39437582660): median 6 and 6 ms, costs less p = 0.12. Below what cpuTimeMs resolves, as expected.
Not covered here, same pattern: per-client parseOptions and mergeUserTypes (about 3% of samples together).
changed the title [-]Every graceful close builds a CONNECTION_CLOSED error that nothing reads[/-][+][FIXED in 4.6.0] Every graceful close builds a CONNECTION_CLOSED error that nothing reads[/+]on Oct 21, 2026
Activity
perf: close a connection without building an error nothing reads
okomarov commentedon Oct 20, 2026
Landed on main in 9ff3b83 (PR #169); ships in the next release.
A graceful close now builds its
CONNECTION_CLOSEDerror only when a COPY stream, afinalcallback, the current or a sent query, an acquisition or a reserved owner will receive it. The pool builds its own inclosedWhileEnding()when a reconnect closes gracefully with queries still queued. The newclosing-no-errorstartup case countsErrors.connectioncalls acrosssql.end()andsql.end({ timeout: 0 }): two before, none now. A first version also replaced anullerror thrown by a socket factory; the Deno job caught it, and the check now applies only toundefined.Measured CPU per request (connect,
select 1, end):errors.jsfalls from 1.3% (fetch_types off) and 1.0% (on) of samples to 0.0%; per-request medians unchanged at 2.53 and 3.46 ms (p = 0.078 and 0.49).cpuTimeMsresolves, as expected.Not covered here, same pattern: per-client
parseOptionsandmergeUserTypes(about 3% of samples together).chore: release 4.6.0-rc1
chore: release 4.6.0
okomarov commentedon Oct 21, 2026
Shipped in 4.6.0 (
npm install @steadybrew/[email protected]), unchanged from 4.6.0-rc1. The tests that cover it passed in the tag run.[-]Every graceful close builds a CONNECTION_CLOSED error that nothing reads[/-][+][FIXED in 4.6.0] Every graceful close builds a CONNECTION_CLOSED error that nothing reads[/+]