fix: prevent token refresh thundering herd#333
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughImplements deduplication of concurrent token refresh requests in Credentials by caching an in-flight promise. When multiple callers request access tokens simultaneously with no cached token available, they now await the same token refresh promise instead of triggering multiple simultaneous token exchanges. Includes test verification for concurrent request behavior. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #333 +/- ##
==========================================
+ Coverage 85.79% 85.82% +0.03%
==========================================
Files 26 26
Lines 1267 1270 +3
Branches 225 250 +25
==========================================
+ Hits 1087 1090 +3
Misses 110 110
Partials 70 70 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #332 by deduplicating concurrent access token refreshes so multiple callers share a single in-flight token exchange instead of triggering parallel requests.
Changes:
- Added an in-flight refresh lock (
refreshAccessTokenPromise) inCredentialsto dedupe concurrent refresh calls. - Added a regression test asserting 5 concurrent
getAccessTokenHeader()calls only trigger 1 token request.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/credentials.test.ts | Adds concurrency regression test for single token exchange under parallel access-token header reads. |
| credentials/credentials.ts | Introduces a shared in-flight refresh promise to prevent concurrent token refresh thundering herd. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Addressed the actionable test-review comment in commit Updated the concurrency regression test to enforce intent directly with nock:
This now verifies both:
Validated locally with:
On the autogenerated-file note: agreed in principle; this PR remains scoped to the runtime fix and test behavior. |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Addressed the actionable review feedback from #333 (review) in commit What changed:
Validation run:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5ab0260 to
b62bdd2
Compare
|
Just resolved the conflicts for this one, |
Summary
Ensures concurrent token header reads share one in-flight refresh instead of issuing parallel token exchange requests.
Changes
refreshAccessTokenPromiselock inCredentialsPotential Breaking Change
Fixes #332
Summary by CodeRabbit