From cd9ea6488829f560dc949a8b2fb789f3cdc05f5d Mon Sep 17 00:00:00 2001 From: Jackson Kearl Date: Wed, 17 Jun 2020 13:06:31 -0700 Subject: [PATCH] Trusted Domains: Timeout filesystem access (#100419) * Adds a timeout for trying to resolve remotes This needs a better fix, but for remote file systems that require auth this can cause issues if auth requires opening a url * Reduce timeout Co-authored-by: Eric Amodio --- .../contrib/url/browser/trustedDomains.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/vs/workbench/contrib/url/browser/trustedDomains.ts b/src/vs/workbench/contrib/url/browser/trustedDomains.ts index 16b960b94cc4f..c3310a3bbbfc2 100644 --- a/src/vs/workbench/contrib/url/browser/trustedDomains.ts +++ b/src/vs/workbench/contrib/url/browser/trustedDomains.ts @@ -144,16 +144,18 @@ export function extractGitHubRemotesFromGitConfig(gitConfig: string): string[] { async function getRemotes(fileService: IFileService, textFileService: ITextFileService, contextService: IWorkspaceContextService): Promise { const workspaceUris = contextService.getWorkspace().folders.map(folder => folder.uri); - const domains = await Promise.all(workspaceUris.map(async workspaceUri => { - const path = workspaceUri.path; - const uri = workspaceUri.with({ path: `${path !== '/' ? path : ''}/.git/config` }); - const exists = await fileService.exists(uri); - if (!exists) { - return []; - } - const gitConfig = (await (textFileService.read(uri, { acceptTextOnly: true }).catch(() => ({ value: '' })))).value; - return extractGitHubRemotesFromGitConfig(gitConfig); - })); + const domains = await Promise.race([ + new Promise(resolve => setTimeout(() => resolve([]), 250)), + Promise.all(workspaceUris.map(async workspaceUri => { + const path = workspaceUri.path; + const uri = workspaceUri.with({ path: `${path !== '/' ? path : ''}/.git/config` }); + const exists = await fileService.exists(uri); + if (!exists) { + return []; + } + const gitConfig = (await (textFileService.read(uri, { acceptTextOnly: true }).catch(() => ({ value: '' })))).value; + return extractGitHubRemotesFromGitConfig(gitConfig); + }))]); const set = domains.reduce((set, list) => list.reduce((set, item) => set.add(item), set), new Set()); return [...set];