Skip to content

Conversation

@sattvikc
Copy link
Collaborator

@sattvikc sattvikc commented Jul 18, 2022

Summary of change

Passing refresh interval to the Keyfunc was causing background goroutine to keep the pointer and also ended up compounding refresh requests over time. Caching JWKS using url -> JWKS map and reusing the instance with each call.

Related issues

Test Plan

Have manually tested that the Apple login works and also ensured the shared instance is getting used for subsequent calls.

Documentation changes

(If relevant, please create a PR in our docs repo, or create a checklist here highlighting the necessary changes)

Checklist for important updates

  • Changelog has been updated
  • coreDriverInterfaceSupported.json file has been updated (if needed)
    • Along with the associated array in supertokens/constants.go
  • frontendDriverInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In supertokens/constants.go > version variable
  • Had installed and ran the pre-commit hook
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.

Remaining TODOs for this PR

@sattvikc sattvikc self-assigned this Jul 18, 2022
@sattvikc sattvikc requested a review from rishabhpoddar July 18, 2022 06:18
Comment on lines 181 to 186
// Create the keyfunc options. Refresh the JWKS every hour and log errors.
refreshInterval := time.Hour
options := keyfunc.Options{
RefreshInterval: refreshInterval,
// https://github.com/supertokens/supertokens-golang/issues/155
// This causes a leak as the pointer to JWKS would be held in the goroutine and
// also results in compounding refresh requests
// RefreshInterval: time.Hour,
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see how other people do this and if this needs to be done in a "global" scope instead of doing it here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use a cache, as that's more efficient compared to this. Have used the standard golang's approach for global stuff.

@sattvikc sattvikc requested a review from rishabhpoddar July 18, 2022 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants