Skip to content

A pool survives losing an idle connection - #10

Merged
SerhiyGreench merged 1 commit into
masterfrom
pools-survive-a-lost-connection
Sep 22, 2026
Merged

SerhiyGreench merged 1 commit into
masterfrom
pools-survive-a-lost-connection

Conversation

@SerhiyGreench

Copy link
Copy Markdown
Member

When the server closes a connection that a pool holds idle (pg_terminate_backend, a failover, a Cloud SQL maintenance restart), pg emits error on the pool itself. dataPool and the audit trail's pool had no listener, so Node exited on the unhandled event and took the whole service down. This happened to a production service when its database was cleaned up underneath it.

Both pools are now guarded by survivesLostConnections, which is exported so a consumer that builds its own pool can use the same guard. The lost connection is reported with console.error; the pool has already dropped the client, and the next checkout opens a fresh one.

Verified against a real Postgres: with no guard, terminating the pool's idle backend crashes the process with Unhandled 'error' event … terminating connection due to administrator command. With dataPool, it logs one line and the next query runs on a new backend. Unit tests cover the guard, dataPool and the barrel.

When the server closes a connection a pool holds idle, pg emits `error`
on the pool itself, and with no listener Node exits on the unhandled
event. dataPool and the audit trail's pool had none, so a
pg_terminate_backend, a failover or a maintenance restart took the whole
service down. Both are now guarded by survivesLostConnections, which is
exported for a consumer building its own pool: the lost connection is
reported, the pool has already dropped it, and the next checkout opens a
fresh one.
@SerhiyGreench
SerhiyGreench merged commit d10a6ab into master Sep 22, 2026
10 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 22, 2026
@SerhiyGreench
SerhiyGreench deleted the pools-survive-a-lost-connection branch September 22, 2026 22:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant