Skip to content

Commit

Permalink
fix: connection leak if wait queue member cancelled
Browse files Browse the repository at this point in the history
A connection could potentially be leaked if a wait queue member was
cancelled (due to timeout) before execution. In these cases we
should return the connection back to the list of connections for
future use or pruning.

NODE-2865
  • Loading branch information
mbroadst committed Nov 3, 2020
1 parent 79df553 commit cafaa1b
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/cmap/connection_pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,18 +477,14 @@ function processWaitQueue(pool) {
if (pool.waitQueueSize && (maxPoolSize <= 0 || pool.totalConnectionCount < maxPoolSize)) {
createConnection(pool, (err, connection) => {
const waitQueueMember = pool[kWaitQueue].shift();
if (waitQueueMember == null) {
if (waitQueueMember == null || waitQueueMember[kCancelled]) {
if (err == null) {
pool[kConnections].push(connection);
}

return;
}

if (waitQueueMember[kCancelled]) {
return;
}

if (err) {
pool.emit('connectionCheckOutFailed', new ConnectionCheckOutFailedEvent(pool, err));
} else {
Expand Down

0 comments on commit cafaa1b

Please sign in to comment.