shell env - timeout after 10s of trying

This commit is contained in:
Benjamin Pasero 2021-06-15 11:48:54 +02:00
parent 505dfc7a06
commit eaf29b7e24
No known key found for this signature in database
GPG key ID: E6380CC4C8219E65
2 changed files with 26 additions and 10 deletions

View file

@ -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

View file

@ -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;