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

This commit is contained in:
Barry Hagan 2025-07-10 14:30:48 -05:00 committed by GitHub
parent 43b8692019
commit 01fadd93d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -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) {

View File

@ -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()
})
)
})