Skip to content

Commit cde05a5

Browse files
authored
feat(auth): extra retry for failed SSO OIDC request #3498
Problem: Sessions may "expire" earlier than expected due to network faults. Solution: Increase retries for InvalidGrantException. Using default retry strategy (exponential backoff) with 2 retries (AWSSDK default), max attempts is now 3.
1 parent c04570a commit cde05a5

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "CodeWhisperer: user is sometimes required to re-login before token expiration"
4+
}

src/credentials/sso/clients.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import { SsoAccessTokenProvider } from './ssoAccessTokenProvider'
3030
import { isClientFault } from '../../shared/errors'
3131
import { DevSettings } from '../../shared/settings'
3232
import { Client } from '@aws-sdk/smithy-client'
33-
import { HttpHandlerOptions } from '@aws-sdk/types'
33+
import { HttpHandlerOptions, SdkError } from '@aws-sdk/types'
3434
import { HttpRequest, HttpResponse } from '@aws-sdk/protocol-http'
35+
import { StandardRetryStrategy, defaultRetryDecider } from '@aws-sdk/middleware-retry'
3536

3637
export class OidcClient {
3738
public constructor(private readonly client: SSOOIDC, private readonly clock: { Date: typeof Date }) {}
@@ -70,9 +71,22 @@ export class OidcClient {
7071
}
7172

7273
public static create(region: string) {
74+
const updatedRetryDecider = (err: SdkError) => {
75+
// Check the default retry conditions
76+
if (defaultRetryDecider(err)) {
77+
return true
78+
}
79+
80+
// Custom retry rules
81+
return err.name === 'InvalidGrantException'
82+
}
7383
const client = new SSOOIDC({
7484
region,
7585
endpoint: DevSettings.instance.get('endpoints', {})['ssooidc'],
86+
retryStrategy: new StandardRetryStrategy(
87+
() => Promise.resolve(3), // Maximum number of retries
88+
{ retryDecider: updatedRetryDecider }
89+
),
7690
})
7791

7892
addLoggingMiddleware(client)

0 commit comments

Comments
 (0)