Skip to content

Commit d616487

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 d616487

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

lib/Pool.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,18 @@ class Pool extends EventEmitter {
302302
*/
303303
_ensureMinimum () {
304304
if (this._draining === true) {
305-
return
305+
return;
306+
}
307+
const minShortfall = this._config.min - this._count;
308+
309+
if(minShortfall == 0){
310+
const waiting = this._waitingClientsQueue.size();
311+
if(waiting > 0){
312+
minShortFall = diff = Math.min(waiting, this._config.max - this._count);
313+
}
306314
}
307-
const minShortfall = this._config.min - this._count
308315
for (let i = 0; i < minShortfall; i++) {
309-
this._createResource()
316+
this._createResource();
310317
}
311318
}
312319

0 commit comments

Comments
 (0)