From 40452ecdcc0a8ffbf75dabcf1065e41fb26456f8 Mon Sep 17 00:00:00 2001 From: Alex Dima Date: Thu, 28 Apr 2022 17:14:19 +0200 Subject: [PATCH] vscode: Fixes microsoft/vscode-remote-release#6543: Go through the unexpected error handler (which has async endless loop protection) instead of using the console in the SIGPIPE handler Commit: ed63059a4752d031535182b1d6eb37719483fbbd --- vscode/src/bootstrap.js | 14 ++++++++------ vscode/src/server-main.js | 6 ++++++ .../server/node/remoteExtensionHostAgentServer.ts | 9 ++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/vscode/src/bootstrap.js b/vscode/src/bootstrap.js index 85e35ab67f707..b2129ea0b2ab8 100644 --- a/vscode/src/bootstrap.js +++ b/vscode/src/bootstrap.js @@ -28,12 +28,14 @@ // increase number of stack frames(from 10, https://github.com/v8/v8/wiki/Stack-Trace-API) Error.stackTraceLimit = 100; - // Workaround for Electron not installing a handler to ignore SIGPIPE - // (https://github.com/electron/electron/issues/13254) - if (typeof process !== 'undefined') { - process.on('SIGPIPE', () => { - console.error(new Error('Unexpected SIGPIPE')); - }); + if (!process.env['VSCODE_HANDLES_SIGPIPE']) { + // Workaround for Electron not installing a handler to ignore SIGPIPE + // (https://github.com/electron/electron/issues/13254) + if (typeof process !== 'undefined') { + process.on('SIGPIPE', () => { + console.error(new Error('Unexpected SIGPIPE')); + }); + } } //#endregion diff --git a/vscode/src/server-main.js b/vscode/src/server-main.js index 0406816534f8d..bb5e3aded35db 100644 --- a/vscode/src/server-main.js +++ b/vscode/src/server-main.js @@ -282,6 +282,12 @@ function loadCode() { delete process.env['ELECTRON_RUN_AS_NODE']; // Keep bootstrap-amd.js from redefining 'fs'. + // See https://github.com/microsoft/vscode-remote-release/issues/6543 + // We would normally install a SIGPIPE listener in bootstrap.js + // But in certain situations, the console itself can be in a broken pipe state + // so logging SIGPIPE to the console will cause an infinite async loop + process.env['VSCODE_HANDLES_SIGPIPE'] = 'true'; + if (process.env['VSCODE_DEV']) { // When running out of sources, we need to load node modules from remote/node_modules, // which are compiled against nodejs, not electron diff --git a/vscode/src/vs/server/node/remoteExtensionHostAgentServer.ts b/vscode/src/vs/server/node/remoteExtensionHostAgentServer.ts index b18fa04dd8610..7532f811127aa 100644 --- a/vscode/src/vs/server/node/remoteExtensionHostAgentServer.ts +++ b/vscode/src/vs/server/node/remoteExtensionHostAgentServer.ts @@ -11,7 +11,7 @@ import { performance } from 'perf_hooks'; import * as url from 'url'; import { LoaderStats } from 'vs/base/common/amd'; import { VSBuffer } from 'vs/base/common/buffer'; -import { setUnexpectedErrorHandler } from 'vs/base/common/errors'; +import { onUnexpectedError, setUnexpectedErrorHandler } from 'vs/base/common/errors'; import { isEqualOrParent } from 'vs/base/common/extpath'; import { Disposable, DisposableStore } from 'vs/base/common/lifecycle'; import { connectionTokenQueryName, FileAccess, Schemas } from 'vs/base/common/network'; @@ -672,6 +672,13 @@ export async function createServer(address: string | net.AddressInfo | null, arg } logService.error(err); }); + process.on('SIGPIPE', () => { + // See https://github.com/microsoft/vscode-remote-release/issues/6543 + // We would normally install a SIGPIPE listener in bootstrap.js + // But in certain situations, the console itself can be in a broken pipe state + // so logging SIGPIPE to the console will cause an infinite async loop + onUnexpectedError(new Error(`Unexpected SIGPIPE`)); + }); }); //