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

[SDK-1912] Unnecessary latency in getTokenSilently with primed cache #558

Merged
merged 2 commits into from
Aug 26, 2020

Conversation

adamjmcgrath
Copy link
Contributor

Description

Check the cache before acquiring lock to avoid latency when the cache is populated (see #552)
Check the cache after acquiring lock to prevent unnecessary requests, because a previous call might have populated the cache while the current call was waiting to acquire the lock (see #480)

References

fixes #552

Testing

To check #552:

Call getTokenSilently with a primed cache, latency should be <20ms

Check regression of #480:

Hammer the getTokenSilently button in the SPA js playground with "Use token cache when fetching new tokens" enabled and check that only one token is requested

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not master

@adamjmcgrath adamjmcgrath requested a review from a team August 26, 2020 09:53
@@ -155,7 +154,7 @@ describe('Auth0', () => {
});

afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

resetAllMocks destroys the localStorage mock (which browser-tabs-lock uses in these tests) clarkbw/jest-localstorage-mock#83

Had to fix some leaky tests after removing it

);

if (cache && cache.access_token) {
await lock.releaseLock(GET_TOKEN_SILENTLY_LOCK_KEY);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will be called in the finally so shouldn't be called here

@adamjmcgrath adamjmcgrath added CH: Fixed PR is fixing a bug medium labels Aug 26, 2020
@adamjmcgrath adamjmcgrath added this to the vNext milestone Aug 26, 2020
@adamjmcgrath adamjmcgrath merged commit d434f73 into master Aug 26, 2020
@adamjmcgrath adamjmcgrath deleted the gts-latency branch August 26, 2020 13:58
@adamjmcgrath adamjmcgrath mentioned this pull request Sep 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CH: Fixed PR is fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getTokenSilently is slow, even with the cache
2 participants