Skip to content

Commit

Permalink
Unref our inmemory-cache expiration timer so that it doesn't hold the…
Browse files Browse the repository at this point in the history
… process open (issue #68).
  • Loading branch information
ploer committed Dec 17, 2014
1 parent aa3dfaa commit 4daf10e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/passport-saml/inmemory-cache-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* @constructor
*/
var CacheProvider = function (options) {

var self = this;
this.cacheKeys = {};

Expand All @@ -28,8 +27,7 @@ var CacheProvider = function (options) {
this.options = options;

// Expire old cache keys
setInterval(function(){

var expirationTimer = setInterval(function(){
var nowMs = new Date().getTime();
var keys = Object.keys(self.cacheKeys);
keys.forEach(function(key){
Expand All @@ -39,6 +37,10 @@ var CacheProvider = function (options) {
});
}, this.options.keyExpirationPeriodMs);

// we only want this to run if the process is still open; it shouldn't hold the process open (issue #68)
// (unref only introduced in node 0.9, so check whether we have it)
if (expirationTimer.unref)
expirationTimer.unref();
};


Expand Down

0 comments on commit 4daf10e

Please sign in to comment.