Skip to content

Commit

Permalink
Clear remove idle timer after destroyAllNow
Browse files Browse the repository at this point in the history
This keeps track of the remove idle timer and will clear the timer
when destroyAllNow is called, as after all clients are destroyed
there is no need to check for idle clients any longer. Without
clearing the timer, a program may have called destroyAllNow because
it was about to exit, but if the remove idle timer still exists,
the event loop will continue running until at most realIntervalMillis.
  • Loading branch information
dougwilson committed Jun 25, 2012
1 parent df2579e commit 173236a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/generic-pool.js
Expand Up @@ -96,6 +96,7 @@ exports.Pool = function (factory) {
waitingClients = new PriorityQueue(factory.priorityRange || 1),
count = 0,
removeIdleScheduled = false,
removeIdleTimer = null,
draining = false,

// Prepare a logger function.
Expand Down Expand Up @@ -176,7 +177,7 @@ exports.Pool = function (factory) {
function scheduleRemoveIdle() {
if (!removeIdleScheduled) {
removeIdleScheduled = true;
setTimeout(removeIdle, reapInterval);
removeIdleTimer = setTimeout(removeIdle, reapInterval);
}
}

Expand Down Expand Up @@ -343,6 +344,8 @@ exports.Pool = function (factory) {
me.destroy(obj.obj);
obj = willDie.shift();
}
removeIdleScheduled = false;
clearTimeout(removeIdleTimer);
if (callback) {
callback();
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -7,7 +7,8 @@
{ "name": "James Cooper", "email": "james@bitmechanic.com" },
{ "name": "Peter Galiba", "email": "poetro@poetro.hu", "url": "http://poetro.hu/" },
{ "name": "Gary Dusbabek" },
{ "name": "Tom MacWright", "url" : "http://www.developmentseed.org/" }
{ "name": "Tom MacWright", "url" : "http://www.developmentseed.org/" },
{ "name": "Douglas Christopher Wilson", "email": "doug@somethingdoug.com", "url" : "http://somethingdoug.com/" }
],
"keywords": ["pool", "pooling", "throttle"],
"main": "lib/generic-pool.js",
Expand Down

0 comments on commit 173236a

Please sign in to comment.