Skip to content

Commit

Permalink
vscode: Fixes microsoft/vscode-remote-release#6543: Go through the un…
Browse files Browse the repository at this point in the history
…expected error handler (which has async endless loop protection) instead of using the console in the SIGPIPE handler

Commit: ed63059a4752d031535182b1d6eb37719483fbbd
  • Loading branch information
Alex Dima authored and sourcegraph-bot committed Apr 28, 2022
1 parent 2672082 commit 40452ec
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
14 changes: 8 additions & 6 deletions vscode/src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions vscode/src/server-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion vscode/src/vs/server/node/remoteExtensionHostAgentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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`));
});
});

//
Expand Down

0 comments on commit 40452ec

Please sign in to comment.