Skip to content

fix #3508 - recheck min client count during idle callback #3509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/pg-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,10 @@ class Pool extends EventEmitter {
let tid
if (this.options.idleTimeoutMillis && this._isAboveMin()) {
tid = setTimeout(() => {
this.log('remove idle client')
this._remove(client, this._pulseQueue.bind(this))
if (this._isAboveMin()) {
this.log('remove idle client')
this._remove(client, this._pulseQueue.bind(this))
}
}, this.options.idleTimeoutMillis)

if (this.options.allowExitOnIdle) {
Expand Down
16 changes: 16 additions & 0 deletions packages/pg-pool/test/sizing.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,19 @@ describe('pool size of 2', () => {
})
)
})

describe('pool min size', () => {
it(
'does not drop below min when clients released at same time',
co.wrap(function* () {
const pool = new Pool({ max: 2, min: 1, idleTimeoutMillis: 10 })
const client = yield pool.connect()
const client2 = yield pool.connect()
client.release()
client2.release()
yield new Promise((resolve) => setTimeout(resolve, 20))
expect(pool.idleCount).to.equal(1)
return yield pool.end()
})
)
})