Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: option to restart with sandbox disabled when workbench launch fails #186265

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions src/vs/platform/windows/electron-main/windowImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import { app, BrowserWindow, BrowserWindowConstructorOptions, Display, Event as ElectronEvent, nativeImage, NativeImage, Rectangle, screen, SegmentedControlSegment, systemPreferences, TouchBar, TouchBarSegmentedControl } from 'electron';
import { DeferredPromise, RunOnceScheduler, timeout } from 'vs/base/common/async';
import { VSBuffer } from 'vs/base/common/buffer';
import { CancellationToken } from 'vs/base/common/cancellation';
import { toErrorMessage } from 'vs/base/common/errorMessage';
import { Emitter } from 'vs/base/common/event';
import { stripComments } from 'vs/base/common/json';
import { Disposable } from 'vs/base/common/lifecycle';
import { FileAccess, Schemas } from 'vs/base/common/network';
import { join } from 'vs/base/common/path';
Expand Down Expand Up @@ -612,6 +614,40 @@ export class CodeWindow extends Disposable implements ICodeWindow {
return this.marketplaceHeadersPromise;
}

private async updateChromiumSandboxEnablement(enable: boolean): Promise<void> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this duplicated from

private async updateCrashReporterEnablement(): Promise<void> {
, would it better to de-duplicate

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be better. How about a reusable method in src/vs/platform/environment/node/argv.ts?


// If disable-chromium-sandbox argv is undefined then this is a fresh start.
try {
const argvContent = await this.fileService.readFile(this.environmentMainService.argvResource);
const argvString = argvContent.value.toString();
const argvJSON = JSON.parse(stripComments(argvString));

// Initial startup
if (argvJSON['disable-chromium-sandbox'] === undefined) {
const additionalArgvContent = [
'',
' // Disables the Chromium sandbox.',
' // Should restart the app if the value is changed.',
` "disable-chromium-sandbox": ${!enable},`,
'}'
];
const newArgvString = argvString.substring(0, argvString.length - 2).concat(',\n', additionalArgvContent.join('\n'));

await this.fileService.writeFile(this.environmentMainService.argvResource, VSBuffer.fromString(newArgvString));
}

// Subsequent startup: update disable-chromium-sandbox value if changed.
else {
const newArgvString = argvString.replace(/"disable-chromium-sandbox": .*,/, `"disable-chromium-sandbox": ${!enable},`);
if (newArgvString !== argvString) {
await this.fileService.writeFile(this.environmentMainService.argvResource, VSBuffer.fromString(newArgvString));
}
}
} catch (error) {
this.logService.error(error);
}
}

private async onWindowError(error: WindowError.UNRESPONSIVE): Promise<void>;
private async onWindowError(error: WindowError.PROCESS_GONE, details: { reason: string; exitCode: number }): Promise<void>;
private async onWindowError(error: WindowError.LOAD, details: { reason: string; exitCode: number }): Promise<void>;
Expand Down Expand Up @@ -707,6 +743,23 @@ export class CodeWindow extends Disposable implements ICodeWindow {
let message: string;
if (!details) {
message = localize('appGone', "The window terminated unexpectedly");
} else if (details.reason === 'launch-failed' && details.exitCode === 18) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we only do this on Windows? Or will this also happen on Linux and macOS?

// Show Dialog
const { response } = await this.dialogMainService.showMessageBox({
type: 'warning',
buttons: [
localize({ key: 'restart', comment: ['&& denotes a mnemonic'] }, "&&Restart")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also have a "Learn more" button to explain the impact further.

],
message: localize('appSandboxError', "Chromium sandbox is unable to create workbench process in your environment"),
detail: localize('appSandboxErrorDetail', "We are sorry for the inconvenience. You can restart the application with chromium sandbox disabled to continue where you left off.")
}, this._win);
if (response === 0) {
this.updateChromiumSandboxEnablement(false);
this.lifecycleMainService.relaunch();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still destroy the window to ensure an orderly shutdown. I would suggest to have another parameter for destroyWindow to trigger a relaunch instead of a reload of the window.

} else {
await this.destroyWindow(false, false);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await this.destroyWindow(false, false);
this.lifecycleMainService.quit();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure? This is to reload a crashed window.

}
return;
} else {
message = localize('appGoneDetails', "The window terminated unexpectedly (reason: '{0}', code: '{1}')", details.reason, details.exitCode ?? '<unknown>');
}
Expand Down
Loading