diff --git a/packages/plugin-ext/package.json b/packages/plugin-ext/package.json index 1717979ad32aa..fd28b2cb4d541 100644 --- a/packages/plugin-ext/package.json +++ b/packages/plugin-ext/package.json @@ -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", @@ -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" diff --git a/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts b/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts index 09cce85b15f1b..0978c2de35b27 100644 --- a/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts +++ b/packages/plugin-ext/src/hosted/node/hosted-plugin-process.ts @@ -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; @@ -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) => { + childProcesses.forEach((p: psTree.PS) => { + process.kill(parseInt(p.PID)); + }); + process.kill(parentPid); + }); } public runPluginServer(): void { diff --git a/yarn.lock b/yarn.lock index 22fc627496b65..1ca99ed0b71bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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: @@ -7833,6 +7838,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"