Skip to content

Commit

Permalink
fix: connection leak if wait queue member cancelled (#2563)
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
jswangjunsheng committed Nov 2, 2020
1 parent ef75502 commit 4018a1e
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions src/cmap/connection_pool.ts
Expand Up @@ -565,18 +565,14 @@ function processWaitQueue(pool: ConnectionPool) {
if (pool.waitQueueSize && (maxPoolSize <= 0 || pool.totalConnectionCount < maxPoolSize)) {
createConnection(pool, (err, connection) => {
const waitQueueMember = pool[kWaitQueue].shift();
if (!waitQueueMember) {
if (!waitQueueMember || waitQueueMember[kCancelled]) {
if (!err && connection) {
pool[kConnections].push(connection);
}

return;
}

if (waitQueueMember[kCancelled]) {
return;
}

if (err) {
pool.emit(
ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
Expand Down

0 comments on commit 4018a1e

Please sign in to comment.