fix stray processes

related to #7527
This commit is contained in:
Joao Moreno 2016-06-15 18:08:25 +02:00
parent 07c5c4aeb4
commit 50b395d959
2 changed files with 25 additions and 12 deletions

15
src/bootstrap.js vendored
View file

@ -109,4 +109,19 @@ process.on('uncaughtException', function (err) {
}
});
// Kill oneself if one's parent dies. Much drama.
if (process.env['VSCODE_PARENT_PID']) {
const parentPid = Number(process.env['VSCODE_PARENT_PID']);
if (typeof parentPid === 'number' && !isNaN(parentPid)) {
setInterval(function () {
try {
process.kill(parentPid, 0); // throws an exception if the main process doesn't exist anymore.
} catch (e) {
process.exit();
}
}, 5000);
}
}
require('./bootstrap-amd').bootstrap(process.env['AMD_ENTRYPOINT']);

View file

@ -104,22 +104,20 @@ export class Client implements IClient, IDisposable {
private get client(): IPCClient {
if (!this._client) {
const args = this.options && this.options.args ? this.options.args : [];
let forkOpts:any = undefined;
const forkOpts = Object.create(null);
if (this.options) {
forkOpts = Object.create(null);
forkOpts.env = assign(clone(process.env), { 'VSCODE_PARENT_PID': String(process.pid) });
if (this.options.env) {
forkOpts.env = assign(clone(process.env), this.options.env);
}
if (this.options && this.options.env) {
forkOpts.env = assign(forkOpts.env, this.options.env);
}
if (typeof this.options.debug === 'number') {
forkOpts.execArgv = ['--nolazy', '--debug=' + this.options.debug];
}
if (this.options && typeof this.options.debug === 'number') {
forkOpts.execArgv = ['--nolazy', '--debug=' + this.options.debug];
}
if (typeof this.options.debugBrk === 'number') {
forkOpts.execArgv = ['--nolazy', '--debug-brk=' + this.options.debugBrk];
}
if (this.options && typeof this.options.debugBrk === 'number') {
forkOpts.execArgv = ['--nolazy', '--debug-brk=' + this.options.debugBrk];
}
this.child = fork(this.modulePath, args, forkOpts);