Skip to content

Commit dc5f52b

Browse files
committed
Prevent permanent waits from destroyed workers
Prevent permanent waits, by ensuring that we continue creating resources if we need them * There are many errors due to pools being configured with min: 0 but then running out of workers while there is still work to do * This results in missed work, infinite loops and timeouts * A solution is to ensure that if we still have work todo that we make sure we still have some workers to do them See: * brianc/node-pg-pool#48 * loopbackio/loopback-connector-postgresql#231 * #175 (Seems related)
1 parent 7865e04 commit dc5f52b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/Pool.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,14 @@ class Pool extends EventEmitter {
304304
if (this._draining === true) {
305305
return
306306
}
307-
const minShortfall = this._config.min - this._count
307+
let minShortfall = this._config.min - this._count
308+
309+
if (minShortfall <= 0) {
310+
const waiting = this._waitingClientsQueue.length
311+
if (waiting > 0) {
312+
minShortfall = Math.min(waiting, this._config.max - this._count)
313+
}
314+
}
308315
for (let i = 0; i < minShortfall; i++) {
309316
this._createResource()
310317
}

0 commit comments

Comments
 (0)