From 56ce780522ad1203d06cfece3b7eff455ec5d4fe Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 11 Oct 2019 17:00:17 -0500 Subject: [PATCH] Prevent process.exit() --- src/node/cli.ts | 10 ++++++++-- src/node/server.ts | 6 +++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/node/cli.ts b/src/node/cli.ts index 1766bdb2e..f505fe505 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -250,13 +250,19 @@ const main = async(): Promise => { return startCli() || new WrapperProcess().start(); }; +const exit = process.exit; +process.exit = function (code?: number) { + const err = new Error(`process.exit() was prevented: ${code || "unknown code"}.`); + console.warn(err.stack); +} as (code?: number) => never; + // It's possible that the pipe has closed (for example if you run code-server // --version | head -1). Assume that means we're done. if (!process.stdout.isTTY) { - process.stdout.on("error", () => process.exit()); + process.stdout.on("error", () => exit()); } main().catch((error) => { logger.error(error.message); - process.exit(typeof error.code === "number" ? error.code : 1); + exit(typeof error.code === "number" ? error.code : 1); }); diff --git a/src/node/server.ts b/src/node/server.ts index 5e3b7cdf0..3de912580 100644 --- a/src/node/server.ts +++ b/src/node/server.ts @@ -653,9 +653,9 @@ export class MainServer extends Server { this._onDidClientConnect.fire({ protocol, onDidClientDisconnect: connection.onClose, }); - // NOTE: We can do this because we only have one connection at a - // time but if that changes we need a way to determine which clients - // belong to a connection and dispose only those. + // TODO: Need a way to match clients with a connection. For now + // dispose everything which only works because no extensions currently + // utilize long-running proxies. (this.services.get(INodeProxyService) as NodeProxyService)._onUp.fire(); connection.onClose(() => (this.services.get(INodeProxyService) as NodeProxyService)._onDown.fire()); } else {