Skip to content

Commit e9f2366

Browse files
committed
Updated connection cleanup process to ensure we cleanup connections that have expired as well as the connections that exceed the config.maxIdle setting
1 parent dee0c08 commit e9f2366

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

lib/pool.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,10 @@ class Pool extends EventEmitter {
200200
this._removeIdleTimeoutConnectionsTimer = setTimeout(() => {
201201
try {
202202
while (
203-
this._freeConnections.length > this.config.maxIdle &&
204-
Date.now() - this._freeConnections.get(0).lastActiveTime >
205-
this.config.idleTimeout
203+
this._freeConnections.length > this.config.maxIdle ||
204+
(this._freeConnections.length > 0 &&
205+
Date.now() - this._freeConnections.get(0).lastActiveTime >
206+
this.config.idleTimeout)
206207
) {
207208
this._freeConnections.get(0).destroy();
208209
}

test/integration/test-pool-release-idle-connection.test.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ pool.getConnection((err1, connection1) => {
3939
connection4.destroy();
4040
pool.end();
4141
});
42-
}, 7000);
42+
// Setting the time to a lower value than idleTimeout will ensure that the connection is not considered idle
43+
// during our assertions
44+
}, 4000);
4345
});
4446
});
4547
});

0 commit comments

Comments
 (0)