From d226599baeec5cabc0b721cf669343dbe4ef2efe Mon Sep 17 00:00:00 2001 From: Sandeep Somavarapu Date: Tue, 9 Dec 2025 09:37:36 +0100 Subject: [PATCH] #260061 fix timeout from get sessions (#282166) --- .../accounts/common/defaultAccount.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/services/accounts/common/defaultAccount.ts b/src/vs/workbench/services/accounts/common/defaultAccount.ts index 9b291e7bf46..42ff1bdca1a 100644 --- a/src/vs/workbench/services/accounts/common/defaultAccount.ts +++ b/src/vs/workbench/services/accounts/common/defaultAccount.ts @@ -15,7 +15,7 @@ import { IContextKey, IContextKeyService, RawContextKey } from '../../../../plat import { Action2, registerAction2 } from '../../../../platform/actions/common/actions.js'; import { localize } from '../../../../nls.js'; import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js'; -import { Barrier } from '../../../../base/common/async.js'; +import { Barrier, timeout } from '../../../../base/common/async.js'; import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js'; import { getErrorMessage } from '../../../../base/common/errors.js'; import { IDefaultAccount } from '../../../../base/common/defaultAccount.js'; @@ -251,7 +251,7 @@ export class DefaultAccountManagementContribution extends Disposable implements } private async findMatchingProviderSession(authProviderId: string, allScopes: string[][]): Promise { - const sessions = await this.authenticationService.getSessions(authProviderId, undefined, undefined, true); + const sessions = await this.getSessions(authProviderId); for (const session of sessions) { this.logService.debug('[DefaultAccount] Checking session with scopes', session.scopes); for (const scopes of allScopes) { @@ -263,6 +263,21 @@ export class DefaultAccountManagementContribution extends Disposable implements return undefined; } + private async getSessions(authProviderId: string): Promise { + for (let attempt = 1; attempt <= 3; attempt++) { + try { + return await this.authenticationService.getSessions(authProviderId, undefined, undefined, true); + } catch (error) { + this.logService.warn(`[DefaultAccount] Attempt ${attempt} to get sessions failed:`, getErrorMessage(error)); + if (attempt === 3) { + throw error; + } + await timeout(500); + } + } + throw new Error('Unable to get sessions after multiple attempts'); + } + private scopesMatch(scopes: ReadonlyArray, expectedScopes: string[]): boolean { return scopes.length === expectedScopes.length && expectedScopes.every(scope => scopes.includes(scope)); }