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 <swt0008411@163.com>
  • Loading branch information
tom-shan committed Jul 31, 2019
1 parent f9ff237 commit 8484930
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/plugin-ext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"getmac": "^1.4.6",
"jsonc-parser": "^2.0.2",
"lodash.clonedeep": "^4.5.0",
"ps-tree": "^1.2.0",
"request": "^2.82.0",
"uuid": "^3.2.1",
"vscode-debugprotocol": "^1.32.0",
Expand Down
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 @@ -129,9 +130,19 @@ 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.pid);
});
}

private killProcessTree(parentPid: number): void {
// tslint:disable-next-line:no-any
psTree(parentPid, (err: Error, childProcesses: Array<any>) => {
// tslint:disable-next-line:no-any
childProcesses.forEach((p: any) => {
process.kill(p.PID);
});
process.kill(parentPid);
});
}

public runPluginServer(): void {
Expand Down
9 changes: 8 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3685,7 +3685,7 @@ etag@~1.8.1:
version "1.8.1"
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"

event-stream@~3.3.0:
event-stream@=3.3.4, event-stream@~3.3.0:
version "3.3.4"
resolved "http://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz#4ab4c9a0f5a54db9338b4c34d86bfce8f4b35571"
dependencies:
Expand Down Expand Up @@ -7833,6 +7833,13 @@ ps-tree@1.1.0:
dependencies:
event-stream "~3.3.0"

ps-tree@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/ps-tree/-/ps-tree-1.2.0.tgz#5e7425b89508736cdd4f2224d028f7bb3f722ebd"
integrity sha512-0VnamPPYHl4uaU/nSFeZZpR21QAWRz+sRv4iW9+v/GS/J5U5iZB5BNN6J0RMoOvdx2gWM2+ZFMIm58q24e4UYA==
dependencies:
event-stream "=3.3.4"

pseudomap@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3"
Expand Down

0 comments on commit 8484930

Please sign in to comment.