Skip to content

Commit 3337709

Browse files
committed
Fixes microsoft/vscode-remote-release#6481: Avoid entering an asynchronous endless loop while handling uncaught exceptions
1 parent c95aa8a commit 3337709

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/vs/server/node/remoteExtensionHostAgentServer.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { performance } from 'perf_hooks';
1111
import * as url from 'url';
1212
import { LoaderStats } from 'vs/base/common/amd';
1313
import { VSBuffer } from 'vs/base/common/buffer';
14+
import { setUnexpectedErrorHandler } from 'vs/base/common/errors';
1415
import { isEqualOrParent } from 'vs/base/common/extpath';
1516
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
1617
import { connectionTokenQueryName, FileAccess, Schemas } from 'vs/base/common/network';
@@ -647,6 +648,22 @@ export async function createServer(address: string | net.AddressInfo | null, arg
647648
const disposables = new DisposableStore();
648649
const { socketServer, instantiationService } = await setupServerServices(connectionToken, args, REMOTE_DATA_FOLDER, disposables);
649650

651+
// Set the unexpected error handler after the services have been initialized, to avoid having
652+
// the telemetry service overwrite our handler
653+
instantiationService.invokeFunction((accessor) => {
654+
const logService = accessor.get(ILogService);
655+
setUnexpectedErrorHandler(err => {
656+
// See https://github.com/microsoft/vscode-remote-release/issues/6481
657+
// In some circumstances, console.error will throw an asynchronous error. This asynchronous error
658+
// will end up here, and then it will be logged again, thus creating an endless asynchronous loop.
659+
// Here we try to break the loop by ignoring EPIPE errors that include our own unexpected error handler in the stack.
660+
if (err && err.code === 'EPIPE' && err.syscall === 'write' && err.stack && /unexpectedErrorHandler/.test(err.stack)) {
661+
return;
662+
}
663+
logService.error(err);
664+
});
665+
});
666+
650667
//
651668
// On Windows, exit early with warning message to users about potential security issue
652669
// if there is node_modules folder under home drive or Users folder.

0 commit comments

Comments
 (0)