From 0e4badbb3a369572c6ab5ef052d165e6ed0924ce Mon Sep 17 00:00:00 2001 From: Vitaliy Gulyy Date: Thu, 7 Jun 2018 16:02:39 +0300 Subject: [PATCH] Fix problem with stopping instance of hosted plugin (#27) Signed-off-by: Vitaliy Gulyy --- .../plugin-ext/src/hosted/node/hosted-plugin-manager.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/plugin-ext/src/hosted/node/hosted-plugin-manager.ts b/packages/plugin-ext/src/hosted/node/hosted-plugin-manager.ts index 74461c9189850..829cd8c7fa977 100644 --- a/packages/plugin-ext/src/hosted/node/hosted-plugin-manager.ts +++ b/packages/plugin-ext/src/hosted/node/hosted-plugin-manager.ts @@ -64,6 +64,7 @@ delete PROCESS_OPTIONS.env.ELECTRON_RUN_AS_NODE; @injectable() export abstract class AbstractHostedPluginManager implements HostedPluginManager { + protected hostedInstanceProcess: cp.ChildProcess; protected processOptions: cp.SpawnOptions; protected isPluginRunnig: boolean = false; @@ -103,7 +104,8 @@ export abstract class AbstractHostedPluginManager implements HostedPluginManager terminate(): void { if (this.isPluginRunnig) { processTree(this.hostedInstanceProcess.pid, (err: Error, children: Array) => { - cp.spawn('kill', ['SIGTERM'].concat(children.map((p: any) => p.PID))); + const args = ['-SIGTERM', this.hostedInstanceProcess.pid.toString()].concat(children.map((p: any) => p.PID)); + cp.spawn('kill', args); }); } else { throw new Error('Hosted plugin instance is not running.'); @@ -163,9 +165,10 @@ export abstract class AbstractHostedPluginManager implements HostedPluginManager this.hostedInstanceProcess.on('error', () => { this.isPluginRunnig = false; }); this.hostedInstanceProcess.on('exit', () => { this.isPluginRunnig = false; }); this.hostedInstanceProcess.stdout.addListener('data', outputListener); + setTimeout(() => { if (!started) { - this.hostedInstanceProcess.kill(); + this.terminate(); this.isPluginRunnig = false; reject('Timeout.'); }