From d616487b881774cdfb85d821e22b4108102df8f2 Mon Sep 17 00:00:00 2001 From: Russ Tyndall Date: Wed, 29 Mar 2017 16:07:26 -0400 Subject: [PATCH] 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: * https://github.com/brianc/node-pg-pool/issues/48 * https://github.com/strongloop/loopback-connector-postgresql/issues/231 * https://github.com/coopernurse/node-pool/issues/175 (Seems related) --- lib/Pool.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/Pool.js b/lib/Pool.js index f60a70e6..54b02f2c 100644 --- a/lib/Pool.js +++ b/lib/Pool.js @@ -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(); } }