From 600294b97e4f108d92528da117397a2f223f1efd Mon Sep 17 00:00:00 2001 From: Daniel Machado Date: Thu, 12 Sep 2024 12:49:42 -0600 Subject: [PATCH 1/2] Add unref to wellknownid to allow script exiting --- src/oauth.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/oauth.js b/src/oauth.js index 5892026..41e5cf6 100644 --- a/src/oauth.js +++ b/src/oauth.js @@ -188,6 +188,7 @@ async function getTokenEndpoints (wellKnown) { } // set cache timeout + // NOTE: added 'unref' to allow scripts to finish when not running package within a server wellKnownTimeoutId = setTimeout(() => { debug.wellKnown('cache expired') getTokenEndpoints(wellKnown) @@ -195,7 +196,7 @@ async function getTokenEndpoints (wellKnown) { debug.wellKnown('unable to refresh well known information') console.error(err.stack) }) - }, cacheDuration * 1000) + }, cacheDuration * 1000).unref() } function revoke (context, token, type) { @@ -209,9 +210,3 @@ function revoke (context, token, type) { url: context.revocationEndpoint }) } - -process.on('exit', () => clearTimeout(wellKnownTimeoutId)) // app is closing -process.on('SIGINT', () => clearTimeout(wellKnownTimeoutId)) // catches ctrl+c event -process.on('SIGBREAK', () => clearTimeout(wellKnownTimeoutId)) // catches Windows ctrl+c event -process.on('SIGUSR1', () => clearTimeout(wellKnownTimeoutId)) // catches "kill pid" -process.on('SIGUSR2', () => clearTimeout(wellKnownTimeoutId)) // catches "kill pid" From 3d57287144a37674e894102c2dcb4650e051080a Mon Sep 17 00:00:00 2001 From: Daniel Machado Date: Fri, 13 Sep 2024 10:28:22 -0600 Subject: [PATCH 2/2] Fix failing tests --- src/oauth.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/oauth.js b/src/oauth.js index 41e5cf6..a6cb8a7 100644 --- a/src/oauth.js +++ b/src/oauth.js @@ -12,7 +12,6 @@ const debug = { } const wellKnownObject = {} -let wellKnownTimeoutId module.exports = async function (clientId, clientSecret, options) { const byuJwt = ByuJwt(options) @@ -189,7 +188,7 @@ async function getTokenEndpoints (wellKnown) { // set cache timeout // NOTE: added 'unref' to allow scripts to finish when not running package within a server - wellKnownTimeoutId = setTimeout(() => { + setTimeout(() => { debug.wellKnown('cache expired') getTokenEndpoints(wellKnown) .catch(err => {