Skip to content

fix(pg-pool): finish requests waiting for a client when the pool ends - #3854

Open
efeesrefinal wants to merge 1 commit into
brianc:masterfrom
efeesrefinal:fix/pool-end-pending
Open

efeesrefinal wants to merge 1 commit into
brianc:masterfrom
efeesrefinal:fix/pool-end-pending

Conversation

@efeesrefinal

Copy link
Copy Markdown

A pool.query() or pool.connect() waiting in the queue never settles if pool.end() is called, and end() still resolves. Once the pool is ending a released client is removed and _pulseQueue returns early, so the queue is never read. This was reported in #3819, which its author closed without a fix.

const pool = new Pool({ max: 1 })
const client = await pool.connect()
const queued = pool.query('SELECT 1') // never settles
const ended = pool.end()
client.release()

Requests queued before end() now run, in line with the existing test pool.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.js that 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 the pg package tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant