Skip to content

Commit

Permalink
Prevent permanent waits, by ensuring that we continue creating
Browse files Browse the repository at this point in the history
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 3a6a34e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/Pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,13 @@ class Pool extends EventEmitter {
return
}
const minShortfall = this._config.min - this._count

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

0 comments on commit 3a6a34e

Please sign in to comment.