@@ -285,34 +285,40 @@ export class RegionProfileManager {
285285 if ( ! previousSelected ) {
286286 return
287287 }
288+
289+ await this . switchRegionProfile ( previousSelected , 'reload' )
290+
288291 // cross-validation
289- this . getProfiles ( )
290- . then ( async ( profiles ) => {
291- const r = profiles . find ( ( it ) => it . arn === previousSelected . arn )
292- if ( ! r ) {
292+ // jitter of 0 ~ 5 second
293+ const jitterInSec = Math . floor ( Math . random ( ) * 6 )
294+ const jitterInMs = jitterInSec * 1000
295+ setTimeout ( async ( ) => {
296+ this . getProfiles ( )
297+ . then ( async ( profiles ) => {
298+ const r = profiles . find ( ( it ) => it . arn === previousSelected . arn )
299+ if ( ! r ) {
300+ telemetry . amazonq_profileState . emit ( {
301+ source : 'reload' ,
302+ amazonQProfileRegion : 'not-set' ,
303+ reason : 'profile could not be selected' ,
304+ result : 'Failed' ,
305+ } )
306+
307+ await this . invalidateProfile ( previousSelected . arn )
308+ RegionProfileManager . logger . warn (
309+ `invlaidating ${ previousSelected . name } profile, arn=${ previousSelected . arn } `
310+ )
311+ }
312+ } )
313+ . catch ( ( e ) => {
293314 telemetry . amazonq_profileState . emit ( {
294315 source : 'reload' ,
295316 amazonQProfileRegion : 'not-set' ,
296- reason : 'profile could not be selected' ,
317+ reason : ( e as Error ) . message ,
297318 result : 'Failed' ,
298319 } )
299-
300- await this . invalidateProfile ( previousSelected . arn )
301- RegionProfileManager . logger . warn (
302- `invlaidating ${ previousSelected . name } profile, arn=${ previousSelected . arn } `
303- )
304- }
305- } )
306- . catch ( ( e ) => {
307- telemetry . amazonq_profileState . emit ( {
308- source : 'reload' ,
309- amazonQProfileRegion : 'not-set' ,
310- reason : ( e as Error ) . message ,
311- result : 'Failed' ,
312320 } )
313- } )
314-
315- await this . switchRegionProfile ( previousSelected , 'reload' )
321+ } , jitterInMs )
316322 }
317323
318324 private loadPersistedRegionProfle ( ) : { [ label : string ] : RegionProfile } {
0 commit comments