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
When pool.end() is called while a caller is waiting in the pool's queue (pool is full, no connectionTimeoutMillis), end() resolves normally but the queued caller's promise never settles.
const{ Pool }=require('pg')constpool=newPool({max: 1})constclient=awaitpool.connect()constqueued=pool.query('select 1')// pool is full, this call waits in the queuesetTimeout(()=>client.release(),50)awaitpool.end()console.log(pool.waitingCount,pool.ended)// 1 trueawaitqueued// never resolves, never rejects
Output:
end resolved; waitingCount = 1 ended = true
queued query: still pending after 5s
Expected: the queued call rejects. The docs say "The pool will return errors when attempting to check out a client after you've called pool.end() on the pool" (docs/pages/features/pooling.mdx). With a connectionTimeoutMillis set the caller eventually gets timeout exceeded when trying to connect, but without one it hangs forever, so a graceful shutdown that awaits in-flight work after pool.end() never finishes.
Cause: _pulseQueue() in the ending branch removes idle clients and sets ended, but never touches _pendingQueue. The existing test pool.end() - finish pending queries uses max: 20 with 20 queries, so nothing is ever queued there.
I can send a PR that rejects every pending item with the existing "Cannot use a pool after calling end on the pool" error, plus a test with a queued waiter, if that's the behaviour you want.
Activity