Skip to content

Remove Stale connections that have not been used for idletimeout. #1749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix eslint errors
  • Loading branch information
aankur committed Aug 30, 2017
commit dd404fe06a898c6a38113b47e7a1d7507101e6e3
16 changes: 8 additions & 8 deletions lib/Pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ function Pool(options) {
function recycleStaleConnections() {
var now = Date.now();
var min = null;
for(var i = 0; i < this._freeConnections.length; i++ ) {
for (var i = 0; i < this._freeConnections.length; i++ ) {
var lastused = this._freeConnections[i]._usedTimestamp;

if(lastused !== undefined) {
if((now - lastused) >= this.config.idleTimeout) {
if (lastused !== undefined) {
if ((now - lastused) >= this.config.idleTimeout) {
this._freeConnections[i].destroy();
i--;
} else {
if(min == null) {
min = now - lastused;
} else {
if((now - lastused) < min) {
if ((now - lastused) < min) {
min = now - lastused;
}
}
}
}
}
if(min != null) {
if(min > 0) {
if (min != null) {
if (min > 0) {
clearInterval(this._recycleTimer);
this._recycleTimer = setInterval(recycleStaleConnections.bind(this),this.config.idleTimeout);
}
Expand Down Expand Up @@ -171,7 +171,7 @@ Pool.prototype.releaseConnection = function releaseConnection(connection) {
throw new Error('Connection already released');
} else {
// add connection to end of free queue
if(this.config.idleTimeout > 0 && this._recycleTimer == null) {
if (this.config.idleTimeout > 0 && this._recycleTimer == null) {
this._recycleTimer = setInterval(recycleStaleConnections.bind(this),this.config.idleTimeout);
}

Expand All @@ -198,7 +198,7 @@ Pool.prototype.releaseConnection = function releaseConnection(connection) {

Pool.prototype.end = function (cb) {
this._closed = true;
if(this._recycleTimer) {
if (this._recycleTimer) {
clearInterval(this._recycleTimer);
this._recycleTimer = null;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/PoolConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ PoolConnection.prototype.end = function () {
+ 'deprecated. In next version calling conn.end() will be '
+ 'restored to default conn.end() behavior. Use '
+ 'conn.release() instead.'
);
);
this.release();
};

Expand Down