Skip to content

Commit c2a2968

Browse files
authored
sandbox - log state of sandboxing for window errors (microsoft#172542)
1 parent 9341903 commit c2a2968

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/vs/platform/windows/electron-main/windowImpl.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
207207
super();
208208

209209
//#region create browser window
210+
let useSandbox = false;
210211
{
211212
// Load window state
212213
const [state, hasMultipleDisplays] = this.restoreWindowState(config.state);
@@ -225,7 +226,6 @@ export class CodeWindow extends Disposable implements ICodeWindow {
225226

226227
const windowSettings = this.configurationService.getValue<IWindowSettings | undefined>('window');
227228

228-
let useSandbox = false;
229229
if (typeof windowSettings?.experimental?.useSandbox === 'boolean') {
230230
useSandbox = windowSettings.experimental.useSandbox;
231231
} else if (this.productService.quality === 'stable' && CodeWindow.sandboxState) {
@@ -442,7 +442,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
442442
this.createTouchBar();
443443

444444
// Eventing
445-
this.registerListeners();
445+
this.registerListeners(useSandbox);
446446
}
447447

448448
setRepresentedFilename(filename: string): void {
@@ -546,12 +546,12 @@ export class CodeWindow extends Disposable implements ICodeWindow {
546546
});
547547
}
548548

549-
private registerListeners(): void {
549+
private registerListeners(sandboxed: boolean): void {
550550

551551
// Window error conditions to handle
552-
this._win.on('unresponsive', () => this.onWindowError(WindowError.UNRESPONSIVE));
553-
this._win.webContents.on('render-process-gone', (event, details) => this.onWindowError(WindowError.PROCESS_GONE, details));
554-
this._win.webContents.on('did-fail-load', (event, exitCode, reason) => this.onWindowError(WindowError.LOAD, { reason, exitCode }));
552+
this._win.on('unresponsive', () => this.onWindowError(WindowError.UNRESPONSIVE, { sandboxed }));
553+
this._win.webContents.on('render-process-gone', (event, details) => this.onWindowError(WindowError.PROCESS_GONE, { ...details, sandboxed }));
554+
this._win.webContents.on('did-fail-load', (event, exitCode, reason) => this.onWindowError(WindowError.LOAD, { reason, exitCode, sandboxed }));
555555

556556
// Prevent windows/iframes from blocking the unload
557557
// through DOM events. We have our own logic for
@@ -648,10 +648,10 @@ export class CodeWindow extends Disposable implements ICodeWindow {
648648
return this.marketplaceHeadersPromise;
649649
}
650650

651-
private async onWindowError(error: WindowError.UNRESPONSIVE): Promise<void>;
652-
private async onWindowError(error: WindowError.PROCESS_GONE, details: { reason: string; exitCode: number }): Promise<void>;
653-
private async onWindowError(error: WindowError.LOAD, details: { reason: string; exitCode: number }): Promise<void>;
654-
private async onWindowError(type: WindowError, details?: { reason: string; exitCode: number }): Promise<void> {
651+
private async onWindowError(error: WindowError.UNRESPONSIVE, details: { sandboxed: boolean }): Promise<void>;
652+
private async onWindowError(error: WindowError.PROCESS_GONE, details: { reason: string; exitCode: number; sandboxed: boolean }): Promise<void>;
653+
private async onWindowError(error: WindowError.LOAD, details: { reason: string; exitCode: number; sandboxed: boolean }): Promise<void>;
654+
private async onWindowError(type: WindowError, details: { reason?: string; exitCode?: number; sandboxed: boolean }): Promise<void> {
655655

656656
switch (type) {
657657
case WindowError.PROCESS_GONE:
@@ -669,6 +669,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
669669
type WindowErrorClassification = {
670670
type: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'The type of window error to understand the nature of the error better.' };
671671
reason: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'The reason of the window error to understand the nature of the error better.' };
672+
sandboxed: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; comment: 'If the window was sandboxed or not.' };
672673
code: { classification: 'SystemMetaData'; purpose: 'PerformanceAndHealth'; isMeasurement: true; comment: 'The exit code of the window process to understand the nature of the error better' };
673674
owner: 'bpasero';
674675
comment: 'Provides insight into reasons the vscode window had an error.';
@@ -677,8 +678,14 @@ export class CodeWindow extends Disposable implements ICodeWindow {
677678
type: WindowError;
678679
reason: string | undefined;
679680
code: number | undefined;
681+
sandboxed: string;
680682
};
681-
this.telemetryService.publicLog2<WindowErrorEvent, WindowErrorClassification>('windowerror', { type, reason: details?.reason, code: details?.exitCode });
683+
this.telemetryService.publicLog2<WindowErrorEvent, WindowErrorClassification>('windowerror', {
684+
type,
685+
reason: details?.reason,
686+
code: details?.exitCode,
687+
sandboxed: details?.sandboxed ? '1' : '0'
688+
});
682689

683690
// Inform User if non-recoverable
684691
switch (type) {
@@ -782,7 +789,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
782789
}
783790
}
784791

785-
private async handleWindowsAdminCrash(details: { reason: string; exitCode: number }) {
792+
private async handleWindowsAdminCrash(details: { reason?: string; exitCode?: number; sandboxed: boolean }) {
786793

787794
// Prepare telemetry event (TODO@bpasero remove me eventually)
788795
const appenders: ITelemetryAppender[] = [];

0 commit comments

Comments
 (0)