Skip to content

Commit 4018a1e

Browse files
fix: connection leak if wait queue member cancelled (#2563)
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 ef75502 commit 4018a1e

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

src/cmap/connection_pool.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,18 +565,14 @@ function processWaitQueue(pool: ConnectionPool) {
565565
if (pool.waitQueueSize && (maxPoolSize <= 0 || pool.totalConnectionCount < maxPoolSize)) {
566566
createConnection(pool, (err, connection) => {
567567
const waitQueueMember = pool[kWaitQueue].shift();
568-
if (!waitQueueMember) {
568+
if (!waitQueueMember || waitQueueMember[kCancelled]) {
569569
if (!err && connection) {
570570
pool[kConnections].push(connection);
571571
}
572572

573573
return;
574574
}
575575

576-
if (waitQueueMember[kCancelled]) {
577-
return;
578-
}
579-
580576
if (err) {
581577
pool.emit(
582578
ConnectionPool.CONNECTION_CHECK_OUT_FAILED,

0 commit comments

Comments
 (0)