From cafaa1b925a0957bd52a3c2a57955387ff6c6b56 Mon Sep 17 00:00:00 2001 From: Matt Broadstone Date: Tue, 3 Nov 2020 10:06:49 -0500 Subject: [PATCH] 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 --- lib/cmap/connection_pool.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/cmap/connection_pool.js b/lib/cmap/connection_pool.js index 45d8adc55c0..a36ee3b6138 100644 --- a/lib/cmap/connection_pool.js +++ b/lib/cmap/connection_pool.js @@ -477,7 +477,7 @@ 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); } @@ -485,10 +485,6 @@ function processWaitQueue(pool) { return; } - if (waitQueueMember[kCancelled]) { - return; - } - if (err) { pool.emit('connectionCheckOutFailed', new ConnectionCheckOutFailedEvent(pool, err)); } else {