.drain() doesn't clear timeouts #17

kkaefer opened this Issue Jul 14, 2011 · 7 comments


None yet

5 participants


Calling .drain() doesn't clear the timeouts set by node-pool. This means node won't exit until all objects expired, even when clearing the pool manually or calling .destroyAllNow()


Seems calling .drain() and .destoryAllNow() together makes node-pool quit reasonably fast. It still waits for one reapInterval though.


Interesting. Do you have a suggested fix? Or perhaps a failing unit test? That would help me reason through the solution.


The reason I reported this is that node-pool prevents my tests from exiting cleanly in a timely fashion. I suggest savig the setTimeout's return value and calling clearTimeout when draining the pool.


I actually missed this issue, but I ran into the same problem and submitted pull request #37 that fixes this.


By the way, the clearing of the reap timeout belongs in destroyAllNow instead of drain because dain just waits for all objects to be returned to the pool and the reap timeout needs to be live when there are objects idle in the pool. destroyAllNow actually destroys all the objects, so since there are no longer objects to reap after a destroyAllNow then the timer can just be canceled. The following is how I end my node scripts with the pool:

pool.drain(function () {
    // Now just waiting for no events on the even loop & exit with code 0

@kkaefer this issue looks closed, right?


closing this as it looks fixed in #37

@sandfox sandfox closed this Jun 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment