Skip to content

Commit

Permalink
fix leaking java debug process
Browse files Browse the repository at this point in the history
When start debugging using vscode java-debug extension,
the debug process will remain in OS process list and
never be killed by theia process if the page is reloaded.

When terminate plugin server, kill all child processes
of plugin-host process.

Signed-off-by: tom-shan <[email protected]>
  • Loading branch information
tom-shan authored and tom-shan committed Jun 2, 2019
1 parent 436b812 commit f00607c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { RPCProtocolImpl } from '../../api/rpc-protocol';
import { MAIN_RPC_CONTEXT } from '../../api/plugin-api';
import { HostedPluginCliContribution } from './hosted-plugin-cli-contribution';
import {HostedPluginProcessesCache} from './hosted-plugin-processes-cache';
const psTree = require('ps-tree');

export interface IPCConnectionOptions {
readonly serverName: string;
Expand Down Expand Up @@ -122,11 +123,21 @@ export class HostedPluginProcess implements ServerPluginRunner {
const hostedPluginManager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT);
hostedPluginManager.$stopPlugin('').then(() => {
emitter.dispose();
cp.kill();
this.killProcessTree(cp);
});

}

private killProcessTree(parentProcess: cp.ChildProcess): void {
const parentPid = parentProcess.pid;
// tslint:disable-next-line:no-any
psTree(parentPid, (err: Error, children: Array<any>) => {
parentProcess.kill();
// tslint:disable-next-line:no-any
cp.spawn('kill', children.map((p: any) => p.PID));
});
}

public runPluginServer(): void {
if (this.childProcess) {
this.terminatePluginServer();
Expand Down

0 comments on commit f00607c

Please sign in to comment.