Skip to content

Commit cafaa1b

Browse files
committedNov 3, 2020
fix: connection leak if wait queue member cancelled
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
1 parent 79df553 commit cafaa1b

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed
 

‎lib/cmap/connection_pool.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,14 @@ function processWaitQueue(pool) {
477477
if (pool.waitQueueSize && (maxPoolSize <= 0 || pool.totalConnectionCount < maxPoolSize)) {
478478
createConnection(pool, (err, connection) => {
479479
const waitQueueMember = pool[kWaitQueue].shift();
480-
if (waitQueueMember == null) {
480+
if (waitQueueMember == null || waitQueueMember[kCancelled]) {
481481
if (err == null) {
482482
pool[kConnections].push(connection);
483483
}
484484

485485
return;
486486
}
487487

488-
if (waitQueueMember[kCancelled]) {
489-
return;
490-
}
491-
492488
if (err) {
493489
pool.emit('connectionCheckOutFailed', new ConnectionCheckOutFailedEvent(pool, err));
494490
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.