-
Notifications
You must be signed in to change notification settings - Fork 28.8k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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'; | ||||||
|
@@ -612,6 +614,40 @@ export class CodeWindow extends Disposable implements ICodeWindow { | |||||
return this.marketplaceHeadersPromise; | ||||||
} | ||||||
|
||||||
private async updateChromiumSandboxEnablement(enable: boolean): Promise<void> { | ||||||
|
||||||
// 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>; | ||||||
|
@@ -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) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||||||
} else { | ||||||
await this.destroyWindow(false, false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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>'); | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this duplicated from
vscode/src/vs/code/electron-main/app.ts
Line 1316 in ac34ea3
There was a problem hiding this comment.
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
?