Repository navigation
fix(pg-pool): finish requests waiting for a client when the pool ends - #3854
efeesrefinal wants to merge 1 commit into
Conversation
|
Ran this branch against the #3819 repro and some variations, since I'd independently hit the same hang. Findings: The fix works for the reported case. On master the queued waiter never settles and One consequence worth a maintainer decision: the drain path can open a brand-new connection after const pool = new Pool({ max: 1 })
const held = await pool.connect()
const waiter = pool.connect() // queued
const ended = pool.end()
held.release(new Error('broken')) // destroyed, not reused
await waiter // served — by a connection created after end()Instrumenting Either way, the error-release path above isn't covered by the test in this PR (which reuses one healthy client for all three queries) — happy to contribute it as a test case if useful. |
A
pool.query()orpool.connect()waiting in the queue never settles ifpool.end()is called, andend()still resolves. Once the pool is ending a released client is removed and_pulseQueuereturns early, so the queue is never read. This was reported in #3819, which its author closed without a fix.Requests queued before
end()now run, in line with the existing testpool.end() - finish pending queries, and the clients are removed once the queue is empty. New checkouts during the drain are still rejected. #3750, a draft, does this too as part of reusing a pool. This is only the fix for the hang, if that helps.Added a test to
ending.jsthat times out without the change. On PostgreSQL 16 and Node 22 the pg-pool tests give 88 passed and 1 failed. The failure is a test that needs pg-native, which I didn't build, and it fails the same way without the change. I did not run thepgpackage tests.