Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unref to wellKnownID to allow script exiting #7

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions src/oauth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const debug = {
}

const wellKnownObject = {}
let wellKnownTimeoutId

module.exports = async function (clientId, clientSecret, options) {
const byuJwt = ByuJwt(options)
Expand Down Expand Up @@ -188,14 +187,15 @@ async function getTokenEndpoints (wellKnown) {
}

// set cache timeout
wellKnownTimeoutId = setTimeout(() => {
// NOTE: added 'unref' to allow scripts to finish when not running package within a server
setTimeout(() => {
debug.wellKnown('cache expired')
getTokenEndpoints(wellKnown)
.catch(err => {
debug.wellKnown('unable to refresh well known information')
console.error(err.stack)
})
}, cacheDuration * 1000)
}, cacheDuration * 1000).unref()
}

function revoke (context, token, type) {
Expand All @@ -209,9 +209,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"
Loading