From eaf29b7e243ca5d68c8cb472f82de6be7e777390 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 15 Jun 2021 11:48:54 +0200 Subject: [PATCH] shell env - timeout after 10s of trying --- src/vs/code/electron-main/app.ts | 10 +------- src/vs/platform/environment/node/shellEnv.ts | 26 +++++++++++++++++++- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index 006c4b79713..625655d9802 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -81,7 +81,6 @@ import { IKeyboardLayoutMainService, KeyboardLayoutMainService } from 'vs/platfo import { NativeParsedArgs } from 'vs/platform/environment/common/argv'; import { isLaunchedFromCli } from 'vs/platform/environment/node/argvHelper'; import { isEqualOrParent } from 'vs/base/common/extpath'; -import { RunOnceScheduler } from 'vs/base/common/async'; import { IExtensionUrlTrustService } from 'vs/platform/extensionManagement/common/extensionUrlTrust'; import { ExtensionUrlTrustService } from 'vs/platform/extensionManagement/node/extensionUrlTrustService'; import { once } from 'vs/base/common/functional'; @@ -998,14 +997,7 @@ export class CodeApplication extends Disposable { // Start to fetch shell environment (if needed) after window has opened // Since this operation can take a long time, we want to warm it up while // the window is opening. - // We also print a warning if the resolution takes longer than 10s. - (async () => { - const slowResolveShellEnvWarning = this._register(new RunOnceScheduler(() => this.logService.warn('Resolving your shell environment is taking more than 10s. Please review your shell configuration. Learn more at https://go.microsoft.com/fwlink/?linkid=2149667.'), 10000)); - slowResolveShellEnvWarning.schedule(); - - await resolveShellEnv(this.logService, this.environmentMainService.args, process.env); - slowResolveShellEnvWarning.dispose(); - })(); + resolveShellEnv(this.logService, this.environmentMainService.args, process.env); // If enable-crash-reporter argv is undefined then this is a fresh start, // based on telemetry.enableCrashreporter settings, generate a UUID which diff --git a/src/vs/platform/environment/node/shellEnv.ts b/src/vs/platform/environment/node/shellEnv.ts index 091bb7e5d38..427119ba5dd 100644 --- a/src/vs/platform/environment/node/shellEnv.ts +++ b/src/vs/platform/environment/node/shellEnv.ts @@ -49,8 +49,32 @@ export async function resolveShellEnv(logService: ILogService, args: NativeParse logService.trace('resolveShellEnv(): running (macOS/Linux)'); } + // Call this only once and cache the promise for + // subsequent calls since this operation can be + // expensive (spawns a process). if (!unixShellEnvPromise) { - unixShellEnvPromise = doResolveUnixShellEnv(logService); + unixShellEnvPromise = new Promise(async resolve => { + + // Give up resolving shell env after 10 seconds + const timeout = setTimeout(() => { + logService.error(`[resolve shell env] Could not resolve shell environment within 10 seconds. Proceeding without shell environment...`); + + resolve({}); + }, 10000); + + // Resolve shell env and handle errors + try { + const shellEnv = await doResolveUnixShellEnv(logService); + + resolve(shellEnv); + } catch (error) { + logService.error(`[resolve shell env] Unable to resolve shell environment (${error}). Proceeding without shell environment...`); + + resolve({}); + } finally { + clearTimeout(timeout); + } + }); } return unixShellEnvPromise;