Repository navigation
Description
Every user callback runs synchronously inside driver internals, so a bug in user code turns into an unrelated failure. Each callback below threw new Error('callback sentinel'), against PostgreSQL 17.11 on Node 24.21.0 in the disposable test container, at 030dc57:
| Callback | First query | Next query on the same pool | Error surfaced? |
|---|---|---|---|
onnotice (during raise notice) |
rejects with the callback's error | succeeds | only as the query's rejection |
onparameter (during set application_name) |
rejects with the callback's error | rejects too: ParameterStatus also arrives at startup, so every new session fails | only as query rejections |
debug |
rejects with the callback's error | hangs: the connection is wedged | only as the query's rejection |
onclose (backend terminated, query queued behind a reservation) |
queued query is still served | succeeds | yes, as an uncaught exception from the socket close event |
The cause is the same throughout. onnotice, onparameter and onnotify run inside handle(), where a throw becomes a protocolError, and errored() rejects whichever query is in flight with the user's error. debug runs while a query is built, so a throw lands in submit()'s catch, the porsager#1082 path. onnotify was not probed.
No upstream issue reports this. Related: porsager#461 (instrumentation hooks) and porsager#1100 (an idle hook for Vercel).
Proposal
Apply one rule to every callback: call it synchronously, catch, and rethrow in a microtask (queueMicrotask(() => { throw e })), as Node's diagnostics_channel does with subscriber errors.
- Driver state is never touched by a user error: no query is rejected with someone else's error, and no session fails or wedges.
- The bug surfaces as an uncaught exception instead of masquerading as a query error.
- try/catch costs nothing on the non-throwing path.
- The call stays synchronous, so async context (for example Vercel's request context) is kept.
The onidle option added for porsager#1100 introduces this guard as a single helper. On that path an unguarded throw is swallowed silently, because no query is in flight. This issue applies the same helper to the existing callbacks, with a regression test per callback. No API change.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsShipped
Activity
feat: add onidle and a Vercel attachDatabasePool adapter
chore: release 4.4.0
[-]A throwing user callback breaks connection state[/-][+][FIXED in 4.4.0] A throwing user callback breaks connection state[/+]