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 kittaakos committed Aug 2, 2019
1 parent 796d642 commit 49f80ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion 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 Expand Up @@ -70,7 +71,8 @@
"devDependencies": {
"@theia/ext-scripts": "^0.9.0",
"@types/decompress": "^4.2.2",
"@types/lodash.clonedeep": "^4.5.3"
"@types/lodash.clonedeep": "^4.5.3",
"@types/ps-tree": "^1.1.0"
},
"nyc": {
"extends": "../../configs/nyc.json"
Expand Down
11 changes: 10 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';
import * as psTree from 'ps-tree';

export interface IPCConnectionOptions {
readonly serverName: string;
Expand Down Expand Up @@ -129,9 +130,17 @@ 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 {
psTree(parentPid, (err: Error, childProcesses: Array<psTree.PS>) => {
childProcesses.forEach((p: psTree.PS) => {
process.kill(parseInt(p.PID));
});
process.kill(parentPid);
});
}

public runPluginServer(): void {
Expand Down
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@
dependencies:
"@types/react" "*"

"@types/ps-tree@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@types/ps-tree/-/ps-tree-1.1.0.tgz#7e2034e8ccdc16f6b0ced7a88529ebcb3b1dc424"
integrity sha512-rm5GU5sefQpg2d/DQ+fMDZnl9aPiJjJ9FYA12isIocNTZqu9VDZRgCRBx3oYFEdmDpmPmY4hxxmY/+1a84Rtzg==

"@types/range-parser@*":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.2.tgz#fa8e1ad1d474688a757140c91de6dace6f4abc8d"
Expand Down Expand Up @@ -3685,7 +3690,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 +7838,13 @@ [email protected]:
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 49f80ff

Please sign in to comment.