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
Commit 25f18be
Browse filesBrowse the repository at this point in the historyBrowse files
fix(postgres): keep the process alive when the server drops a checked-out connection (#480)
pg-pool only listens for a client's 'error' while the client is idle:
the listener is removed on checkout and re-attached on release. When the
server ends the connection while a query is in flight, pg emits 'error'
on the Client itself, and with nobody listening Node reports an
unhandled 'error' event and exits the whole DBHub process. #423 added
a pool-level listener, which only covers idle clients.
The reported trigger is a multi-statement batch whose second statement
runs pg_terminate_backend(pg_backend_pid()): the ROLLBACK sent by
rollbackQuietly is still queued when the socket closes, so the client
is checked out when the event fires. The same window exists for a
single statement under readonly (BEGIN READ ONLY takes the same path,
and the plugin/MCPB bundles are read-only by default), and for any
drop that arrives as a socket error without a FATAL message first
(failover, proxy reset), where even a plain single statement crashes.
Route every pool.connect() through acquireClient(), which attaches a
client-level 'error' listener for the whole checkout and passes the
captured error to release() so pg-pool closes and discards the client
instead of handing the dead connection to the next caller. This mirrors
what pool.query() already does for its own checkout.
Adds a loopback protocol-level test that ends the connection mid-batch,
inside a READ ONLY transaction, and by a bare socket reset, and checks
that the tool call errors, the process survives, and the next query gets
a fresh connection. The two pool mocks now expose the EventEmitter
surface a real pg.Client has.
Fixes#479
Claude-Session: https://claude.ai/code/session_017Eyu55gHK6LVo6am2nvCrz
Co-authored-by: Claude <noreply@anthropic.com>
0 commit comments