Skip to content

Commit

Permalink
vscode-server crashes, if there is no network interface with a valid …
Browse files Browse the repository at this point in the history
…mac address present (#176368)
  • Loading branch information
aeschli committed Mar 8, 2023
1 parent f0a25d6 commit 155b155
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions src/vs/server/node/remoteExtensionHostAgentServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -666,14 +666,10 @@ export async function createServer(address: string | net.AddressInfo | null, arg
console.warn(connectionToken.message);
process.exit(1);
}
const disposables = new DisposableStore();
const { socketServer, instantiationService } = await setupServerServices(connectionToken, args, REMOTE_DATA_FOLDER, disposables);

// Set the unexpected error handler after the services have been initialized, to avoid having
// the telemetry service overwrite our handler
let didLogAboutSIGPIPE = false;
instantiationService.invokeFunction((accessor) => {
const logService = accessor.get(ILogService);
// setting up error handlers, first with console.error, then, once available, using the log service

function initUnexpectedErrorHandler(handler: (err: any) => void) {
setUnexpectedErrorHandler(err => {
// See https://github.com/microsoft/vscode-remote-release/issues/6481
// In some circumstances, console.error will throw an asynchronous error. This asynchronous error
Expand All @@ -682,18 +678,38 @@ export async function createServer(address: string | net.AddressInfo | null, arg
if (isSigPipeError(err) && err.stack && /unexpectedErrorHandler/.test(err.stack)) {
return;
}
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
if (!didLogAboutSIGPIPE) {
didLogAboutSIGPIPE = true;
onUnexpectedError(new Error(`Unexpected SIGPIPE`));
}
handler(err);
});
}

const unloggedErrors: any[] = [];
initUnexpectedErrorHandler((error: any) => {
unloggedErrors.push(error);
console.error(error);
});
let didLogAboutSIGPIPE = false;
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
if (!didLogAboutSIGPIPE) {
didLogAboutSIGPIPE = true;
onUnexpectedError(new Error(`Unexpected SIGPIPE`));
}
});

const disposables = new DisposableStore();
const { socketServer, instantiationService } = await setupServerServices(connectionToken, args, REMOTE_DATA_FOLDER, disposables);

// Set the unexpected error handler after the services have been initialized, to avoid having
// the telemetry service overwrite our handler
instantiationService.invokeFunction((accessor) => {
const logService = accessor.get(ILogService);
unloggedErrors.forEach(error => logService.error(error));
unloggedErrors.length = 0;

initUnexpectedErrorHandler((error: any) => logService.error(error));
});

//
Expand Down

0 comments on commit 155b155

Please sign in to comment.