diff --git a/lib/passport-saml/inmemory-cache-provider.js b/lib/passport-saml/inmemory-cache-provider.js index 7cafbae0..ccef11c5 100644 --- a/lib/passport-saml/inmemory-cache-provider.js +++ b/lib/passport-saml/inmemory-cache-provider.js @@ -13,7 +13,6 @@ * @constructor */ var CacheProvider = function (options) { - var self = this; this.cacheKeys = {}; @@ -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){ @@ -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(); };