Skip to content

Commit 56ce780

Browse files
committed
Prevent process.exit()
1 parent 567010e commit 56ce780

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/node/cli.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,19 @@ const main = async(): Promise<boolean | void | void[]> => {
250250
return startCli() || new WrapperProcess().start();
251251
};
252252

253+
const exit = process.exit;
254+
process.exit = function (code?: number) {
255+
const err = new Error(`process.exit() was prevented: ${code || "unknown code"}.`);
256+
console.warn(err.stack);
257+
} as (code?: number) => never;
258+
253259
// It's possible that the pipe has closed (for example if you run code-server
254260
// --version | head -1). Assume that means we're done.
255261
if (!process.stdout.isTTY) {
256-
process.stdout.on("error", () => process.exit());
262+
process.stdout.on("error", () => exit());
257263
}
258264

259265
main().catch((error) => {
260266
logger.error(error.message);
261-
process.exit(typeof error.code === "number" ? error.code : 1);
267+
exit(typeof error.code === "number" ? error.code : 1);
262268
});

src/node/server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,9 @@ export class MainServer extends Server {
653653
this._onDidClientConnect.fire({
654654
protocol, onDidClientDisconnect: connection.onClose,
655655
});
656-
// NOTE: We can do this because we only have one connection at a
657-
// time but if that changes we need a way to determine which clients
658-
// belong to a connection and dispose only those.
656+
// TODO: Need a way to match clients with a connection. For now
657+
// dispose everything which only works because no extensions currently
658+
// utilize long-running proxies.
659659
(this.services.get(INodeProxyService) as NodeProxyService)._onUp.fire();
660660
connection.onClose(() => (this.services.get(INodeProxyService) as NodeProxyService)._onDown.fire());
661661
} else {

0 commit comments

Comments
 (0)