-
Notifications
You must be signed in to change notification settings - Fork 477
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
fix(auth): debounce getToken() function #6282
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
hayemaxi
approved these changes
Dec 30, 2024
Problem: The Identity team noticed a large spike in token refreshes for specific users. One user would trigger refresh over 50 times within a few seconds. Solution: The telemetry showed that `getChatAuthState()` was being called many times in a short period. This eventually triggered the token refresh logic many times, if the token was expired. The solution is to add a debounce to `getToken()` which calls the refresh logic. - `debounce()` only accepts functions without any args, the refresh logic requires args - `getToken()` will also load from disk is the token is not expired, so debouncing here saves disk I/O as well. The current debounce interval is 100 milliseconds, which based on telemetry should be enough to capture the barrage of calls. Signed-off-by: nkomonen-amazon <nkomonen@amazon.com>
Problem: By default a sinon fake clock was installed on all tests. This caused the new debounce functionality on getToken to freeze since the clock was not progressed, multiple tests were failing. Solution: Only use the fake clock in tests that need it Signed-off-by: nkomonen-amazon <nkomonen@amazon.com>
Signed-off-by: nkomonen-amazon <nkomonen@amazon.com>
nkomonen-amazon
force-pushed
the
refreshTokenSpam
branch
from
January 7, 2025 23:55
ce410ea
to
6bcf269
Compare
- Removed unnecessary fake clock. I guess this existed for historical reasons but is not needed anymore - Refactored one of the methods so that it could be stubbed Signed-off-by: nkomonen-amazon <nkomonen@amazon.com>
/retryBuilds |
We can now spy on the underlying getToken method to verify it is being debounced as expected. Also reduce the debounce interval to 50ms to reduce the delay but still catch a barrage of calls Signed-off-by: nkomonen-amazon <nkomonen@amazon.com>
/retryBuilds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
The Identity team noticed a large spike in token refreshes for specific users. One user would trigger refresh over 50 times within a few seconds.
Ticket:
P180886632
Solution:
The telemetry showed that
getChatAuthState()
was being called many times in a short period. This eventually triggered the token refresh logic many times, if the token was expired.The solution is to add a debounce to
getToken()
which calls the refresh logic.debounce()
only accepts functions without any args, the refresh logic requires argsgetToken()
will also load from disk is the token is not expired, so debouncing here saves disk I/O as well.The current debounce interval is 100 milliseconds, which based on telemetry should be enough to capture the barrage of calls. With some manual testing it does not feel like UX is impacted in any noticeable way.
feature/x
branches will not be squash-merged at release time.