Skip to content

Commit 8748594

Browse files
committedOct 29, 2019
Kill inner process if parent process dies
Fixes #1076.
1 parent 7e4a73c commit 8748594

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎src/node/cli.ts

+15
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ export class WrapperProcess {
237237
env: {
238238
...process.env,
239239
LAUNCH_VSCODE: "true",
240+
VSCODE_PARENT_PID: process.pid.toString(),
240241
},
241242
stdio: ["inherit", "inherit", "inherit", "ipc"],
242243
});
@@ -257,6 +258,20 @@ process.exit = function (code?: number) {
257258
console.warn(err.stack);
258259
} as (code?: number) => never;
259260

261+
// Copy the extension host behavior of killing oneself if the parent dies. This
262+
// also exists in bootstrap-fork.js but spawning with that won't work because we
263+
// override process.exit.
264+
if (typeof process.env.VSCODE_PARENT_PID !== "undefined") {
265+
const parentPid = parseInt(process.env.VSCODE_PARENT_PID, 10);
266+
setInterval(() => {
267+
try {
268+
process.kill(parentPid, 0); // Throws an exception if the process doesn't exist anymore.
269+
} catch (e) {
270+
exit();
271+
}
272+
}, 5000);
273+
}
274+
260275
// It's possible that the pipe has closed (for example if you run code-server
261276
// --version | head -1). Assume that means we're done.
262277
if (!process.stdout.isTTY) {

0 commit comments

Comments
 (0)
Please sign in to comment.