Skip to content

Commit

Permalink
Updated connection cleanup process to ensure we cleanup connections t…
Browse files Browse the repository at this point in the history
…hat have expired as well as the connections that exceed the config.maxIdle setting
  • Loading branch information
robertpitt committed Sep 7, 2024
1 parent dee0c08 commit e9f2366
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ class Pool extends EventEmitter {
this._removeIdleTimeoutConnectionsTimer = setTimeout(() => {
try {
while (
this._freeConnections.length > this.config.maxIdle &&
Date.now() - this._freeConnections.get(0).lastActiveTime >
this.config.idleTimeout
this._freeConnections.length > this.config.maxIdle ||
(this._freeConnections.length > 0 &&
Date.now() - this._freeConnections.get(0).lastActiveTime >
this.config.idleTimeout)
) {
this._freeConnections.get(0).destroy();
}
Expand Down
4 changes: 3 additions & 1 deletion test/integration/test-pool-release-idle-connection.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ pool.getConnection((err1, connection1) => {
connection4.destroy();
pool.end();
});
}, 7000);
// Setting the time to a lower value than idleTimeout will ensure that the connection is not considered idle
// during our assertions
}, 4000);
});
});
});

0 comments on commit e9f2366

Please sign in to comment.