Skip to content

Commit

Permalink
Prevent permanent waits from destroyed workers
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
bobbysmith007 committed Mar 29, 2017
1 parent 7865e04 commit d616487
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/Pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,18 @@ class Pool extends EventEmitter {
*/
_ensureMinimum () {
if (this._draining === true) {
return
return;
}
const minShortfall = this._config.min - this._count;

if(minShortfall == 0){
const waiting = this._waitingClientsQueue.size();
if(waiting > 0){
minShortFall = diff = Math.min(waiting, this._config.max - this._count);
}
}
const minShortfall = this._config.min - this._count
for (let i = 0; i < minShortfall; i++) {
this._createResource()
this._createResource();
}
}

Expand Down

0 comments on commit d616487

Please sign in to comment.