Skip to content

Commit

Permalink
Fix problem with stopping instance of hosted plugin (#27)
Browse files Browse the repository at this point in the history
Signed-off-by: Vitaliy Gulyy <vguliy@codenvy.com>
  • Loading branch information
Vitaliy Gulyy authored and benoitf committed Jun 20, 2018
1 parent de83517 commit 0e4badb
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/plugin-ext/src/hosted/node/hosted-plugin-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +104,8 @@ export abstract class AbstractHostedPluginManager implements HostedPluginManager
terminate(): void {
if (this.isPluginRunnig) {
processTree(this.hostedInstanceProcess.pid, (err: Error, children: Array<any>) => {
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.');
Expand Down Expand Up @@ -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.');
}
Expand Down

0 comments on commit 0e4badb

Please sign in to comment.