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 {