Skip to content

Commit d226599

Browse files
authored
#260061 fix timeout from get sessions (#282166)
1 parent e605ba2 commit d226599

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/vs/workbench/services/accounts/common/defaultAccount.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IContextKey, IContextKeyService, RawContextKey } from '../../../../plat
1515
import { Action2, registerAction2 } from '../../../../platform/actions/common/actions.js';
1616
import { localize } from '../../../../nls.js';
1717
import { IWorkbenchContribution, registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js';
18-
import { Barrier } from '../../../../base/common/async.js';
18+
import { Barrier, timeout } from '../../../../base/common/async.js';
1919
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
2020
import { getErrorMessage } from '../../../../base/common/errors.js';
2121
import { 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

Comments
 (0)