1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-28 21:25:25 +00:00

Kill inner process if parent process dies

Fixes #1076.
This commit is contained in:
Asher 2019-10-29 14:41:18 -05:00
parent 7e4a73ce2d
commit 87485948ad
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A

View File

@ -237,6 +237,7 @@ export class WrapperProcess {
env: {
...process.env,
LAUNCH_VSCODE: "true",
VSCODE_PARENT_PID: process.pid.toString(),
},
stdio: ["inherit", "inherit", "inherit", "ipc"],
});
@ -257,6 +258,20 @@ process.exit = function (code?: number) {
console.warn(err.stack);
} as (code?: number) => never;
// Copy the extension host behavior of killing oneself if the parent dies. This
// also exists in bootstrap-fork.js but spawning with that won't work because we
// override process.exit.
if (typeof process.env.VSCODE_PARENT_PID !== "undefined") {
const parentPid = parseInt(process.env.VSCODE_PARENT_PID, 10);
setInterval(() => {
try {
process.kill(parentPid, 0); // Throws an exception if the process doesn't exist anymore.
} catch (e) {
exit();
}
}, 5000);
}
// 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) {