Skip to content

pool.end() leaves queued connect()/query() callers pending forever #3819

Closed

Description

@YOGESH256

Versions: pg 8.22.0 / pg-pool 3.14.0, Node 20.18.0, PostgreSQL 17.5

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')

const pool = new Pool({ max: 1 })
const client = await pool.connect()
const queued = pool.query('select 1') // pool is full, this call waits in the queue
setTimeout(() => client.release(), 50)

await pool.end()
console.log(pool.waitingCount, pool.ended) // 1 true

await queued // 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.

Related: #3635 (end() semantics).

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions