Skip to content

Commit b7abd67

Browse files
committed
Fix pool queue dequeuing loop
This resolves a problem introduced with the pool.reconfigure() enhancement.
1 parent 901c50c commit b7abd67

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/pool.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ const util = require('util');
2727
// _checkRequestQueue()
2828
// When a connection is returned to the pool, this method is called (via an
2929
// event handler) to determine when requests for connections should be
30-
// completed and cancels any timeout that may have been associated with the
30+
// resumed and cancels any timeout that may have been associated with the
3131
// request. This method is also called from reconfigure() so that waiting
32-
// connection-requests can be processed.
32+
// connection requests can be processed. Note the use of a local variable for
33+
// the number of connections out. This is because the connection requests will
34+
// not resume until after the loop is finished, and therefore the number of
35+
// connections the pool thinks is out will not be incremented.
3336
//-----------------------------------------------------------------------------
3437
function _checkRequestQueue() {
35-
while (this._connRequestQueue.length > 0 &&
36-
this._connectionsOut < this.poolMax) {
37-
// process the payload
38+
let connectionsOut = this._connectionsOut;
39+
while (this._connRequestQueue.length > 0 && connectionsOut < this.poolMax) {
40+
connectionsOut += 1;
3841
const payload = this._connRequestQueue.shift();
3942
if (this._enableStatistics) {
4043
this._totalRequestsDequeued += 1;

0 commit comments

Comments
 (0)