@@ -15,7 +15,7 @@ import { IContextKey, IContextKeyService, RawContextKey } from '../../../../plat
1515import { Action2 , registerAction2 } from '../../../../platform/actions/common/actions.js' ;
1616import { localize } from '../../../../nls.js' ;
1717import { IWorkbenchContribution , registerWorkbenchContribution2 , WorkbenchPhase } from '../../../common/contributions.js' ;
18- import { Barrier } from '../../../../base/common/async.js' ;
18+ import { Barrier , timeout } from '../../../../base/common/async.js' ;
1919import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js' ;
2020import { getErrorMessage } from '../../../../base/common/errors.js' ;
2121import { IDefaultAccount } from '../../../../base/common/defaultAccount.js' ;
@@ -251,7 +251,7 @@ export class DefaultAccountManagementContribution extends Disposable implements
251251 }
252252
253253 private async findMatchingProviderSession ( authProviderId : string , allScopes : string [ ] [ ] ) : Promise < AuthenticationSession | undefined > {
254- const sessions = await this . authenticationService . getSessions ( authProviderId , undefined , undefined , true ) ;
254+ const sessions = await this . getSessions ( authProviderId ) ;
255255 for ( const session of sessions ) {
256256 this . logService . debug ( '[DefaultAccount] Checking session with scopes' , session . scopes ) ;
257257 for ( const scopes of allScopes ) {
@@ -263,6 +263,21 @@ export class DefaultAccountManagementContribution extends Disposable implements
263263 return undefined ;
264264 }
265265
266+ private async getSessions ( authProviderId : string ) : Promise < readonly AuthenticationSession [ ] > {
267+ for ( let attempt = 1 ; attempt <= 3 ; attempt ++ ) {
268+ try {
269+ return await this . authenticationService . getSessions ( authProviderId , undefined , undefined , true ) ;
270+ } catch ( error ) {
271+ this . logService . warn ( `[DefaultAccount] Attempt ${ attempt } to get sessions failed:` , getErrorMessage ( error ) ) ;
272+ if ( attempt === 3 ) {
273+ throw error ;
274+ }
275+ await timeout ( 500 ) ;
276+ }
277+ }
278+ throw new Error ( 'Unable to get sessions after multiple attempts' ) ;
279+ }
280+
266281 private scopesMatch ( scopes : ReadonlyArray < string > , expectedScopes : string [ ] ) : boolean {
267282 return scopes . length === expectedScopes . length && expectedScopes . every ( scope => scopes . includes ( scope ) ) ;
268283 }
0 commit comments