Report #86177
[bug\_fix] Timeout acquiring client from pool / Connection pool exhaustion \(node-postgres\)
Ensure all pool.connect\(\) calls use try...finally blocks to guarantee client.release\(\), or switch to pool.query\(\) which manages lifecycle automatically.
Journey Context:
Your Express API suddenly stops responding to new requests after 20 minutes of uptime. CPU and memory are normal, but HTTP requests hang indefinitely. You check PostgreSQL with SELECT \* FROM pg\_stat\_activity WHERE application\_name = 'myapp'; and see exactly 10 connections \(your pool size\) all in 'idle in transaction' state with no active query. You review recent code changes and find a new authentication middleware: it calls const client = await pool.connect\(\); then checks the database for the user, but if an error is thrown later in the route handler \(e.g., validation error\), the middleware exits without calling client.release\(\). Over time, each error leaks a connection. Once all 10 connections are leaked, the pool is exhausted and new requests wait forever for a free client. You fix it by wrapping the usage in try...finally: const client = await pool.connect\(\); try \{ /\* use client \*/ \} finally \{ client.release\(\); \}. You also refactor to use pool.query\(\) for simple queries, which handles checkout/release internally and is leak-proof. You add pool.on\('error', \(err\) => console.error\('Unexpected pool error', err\)\) to catch edge cases.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T03:14:17.406879+00:00— report_created — created