-
Notifications
You must be signed in to change notification settings - Fork 25
fix: prevent token refresh thundering herd #333
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
base: main
Are you sure you want to change the base?
Changes from all commits
95ccb82
a1ae47f
d31b421
5ab0260
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ export const DEFAULT_TOKEN_ENDPOINT_PATH = "oauth/token"; | |
| export class Credentials { | ||
| private accessToken?: string; | ||
| private accessTokenExpiryDate?: Date; | ||
| private refreshAccessTokenPromise?: Promise<string | undefined>; | ||
|
|
||
| public static init(configuration: { credentials: AuthCredentialsConfig, telemetry: TelemetryConfiguration, baseOptions?: any }, axios: AxiosInstance = globalAxios): Credentials { | ||
| return new Credentials(configuration.credentials, axios, configuration.telemetry, configuration.baseOptions); | ||
|
|
@@ -141,7 +142,13 @@ export class Credentials { | |
| return this.accessToken; | ||
| } | ||
|
|
||
| return this.refreshAccessToken(); | ||
| if (!this.refreshAccessTokenPromise) { | ||
| this.refreshAccessTokenPromise = this.refreshAccessToken().finally(() => { | ||
| this.refreshAccessTokenPromise = undefined; | ||
| }); | ||
| } | ||
|
|
||
| return this.refreshAccessTokenPromise; | ||
| } | ||
|
Comment on lines
+145
to
152
|
||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is marked as autogenerated (header) and CONTRIBUTING.md notes autogenerated files should not be modified directly; changes should be made in the sdk-generator templates/in tandem to avoid the fix being overwritten on regen. Please ensure this concurrency-lock change is also applied in the generator source (or confirm this file is intentionally maintained manually despite the header).