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 dc5f52b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,14 @@ class Pool extends EventEmitter {
if (this._draining === true) {
return
}
const minShortfall = this._config.min - this._count
let minShortfall = this._config.min - this._count

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

0 comments on commit dc5f52b

Please sign in to comment.