mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Immediately unref() maxLifetimeSeconds Timeout object to prevent blocking allowExitOnIdle (#2721)
This commit is contained in:
parent
c7743646cd
commit
3ca56027d3
@ -252,7 +252,7 @@ class Pool extends EventEmitter {
|
||||
this.log('new client connected')
|
||||
|
||||
if (this.options.maxLifetimeSeconds !== 0) {
|
||||
setTimeout(() => {
|
||||
const maxLifetimeTimeout = setTimeout(() => {
|
||||
this.log('ending client due to expired lifetime')
|
||||
this._expired.add(client)
|
||||
const idleIndex = this._idle.findIndex((idleItem) => idleItem.client === client)
|
||||
@ -265,6 +265,9 @@ class Pool extends EventEmitter {
|
||||
)
|
||||
}
|
||||
}, this.options.maxLifetimeSeconds * 1000)
|
||||
|
||||
maxLifetimeTimeout.unref()
|
||||
client.once('end', () => clearTimeout(maxLifetimeTimeout))
|
||||
}
|
||||
|
||||
return this._acquireClient(client, pendingItem, idleListener, true)
|
||||
|
||||
@ -3,7 +3,7 @@ if (module === require.main) {
|
||||
const allowExitOnIdle = process.env.ALLOW_EXIT_ON_IDLE === '1'
|
||||
const Pool = require('../index')
|
||||
|
||||
const pool = new Pool({ idleTimeoutMillis: 200, ...(allowExitOnIdle ? { allowExitOnIdle: true } : {}) })
|
||||
const pool = new Pool({ maxLifetimeSeconds: 2, idleTimeoutMillis: 200, ...(allowExitOnIdle ? { allowExitOnIdle: true } : {}) })
|
||||
pool.query('SELECT NOW()', (err, res) => console.log('completed first'))
|
||||
pool.on('remove', () => {
|
||||
console.log('removed')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user