-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #5279 Leaking java debug process #5281
Conversation
fix #5279 |
cdadffd
to
534fb55
Compare
@benoitf @evidolob @akosyakov Would you mind reviewing this PR? |
@@ -120,13 +121,22 @@ export class HostedPluginProcess implements ServerPluginRunner { | |||
} | |||
}); | |||
const hostedPluginManager = rpc.getProxy(MAIN_RPC_CONTEXT.HOSTED_PLUGIN_MANAGER_EXT); | |||
this.killChildProcesses(cp.pid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should go in then
case after after plugin got unloaded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I don't think it is really resolves the issue. Usually child process should observe parent process and if it exist then exit as well. Killing child processes from a parent process does not guarantee that it will happens always, e.g. if a parent process crashes it won't have a chance of doing it. I'm pretty sure that vscode java debug extension already has this logic, otherwise it won't work in VS Code as well. It bothers me why debug process exits only when a main server process dies. It seems that propagation of parent process id is done bogusly. |
@tom-shan you are right, just got the same |
Will this problem happen also when two clients connect together? Like two different browsers. |
I don't think it is related to the plugin system. When 2 users connect to the same backend they cannot expect to run anything on the same ports. Regarding debugging there is an issue to make debug session shared by default. That each client for the same workspace see all running debug sessions. |
Hi @akosyakov, it seems like no other questions, could you help merge this PR? |
parentProcess.disconnect(); | ||
const parentPid = parentProcess.pid; | ||
if (isWindows) { | ||
cp.spawn('taskkill', ['/F', '/T', '/PID', parentPid.toString()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a very similar issue in one of my downstream projects. A few remarks on the PR:
- Instead of doing
taskkill
on Windows andkill
on *nix, just usetree-kill
:
require('tree-kill')(yourPID);
- You have to get the process tree on Windows as well. Not just in the
else
branch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interesting that VS Code uses taskkill
for it: https://github.com/microsoft/vscode/blob/a848f18df4efa9eb947bd01cbebcede418e66148/src/vs/workbench/contrib/debug/node/debugAdapter.ts#L269-L275
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, i see tree-kill does it https://github.com/pkrumins/node-tree-kill/blob/master/index.js#L20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your recommendation, I will try to use this new npm package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tom-shan, please ping if you are done, I'll try to find time for the verification. Thanks!
@tom-shan sorry, we still had not time to test this PR on different platforms @kittaakos could we rebase, test it as it is and merge? or you will prefer to use Could you verify on windows please? In order to test one can install nodejs vscode extensions (https://marketplace.visualstudio.com/items?itemName=ms-vscode.node-debug + https://marketplace.visualstudio.com/items?itemName=ms-vscode.node-debug2) instead of native ( |
@kittaakos @akosyakov Please have a review. |
Sorry for the confusion, @tom-shan. I think what you did for the non-Windows version was the right way: you have to kill the children of the process you want to terminate, then the process. Something like this: private killChildProcesses(parentPid: number): void {
psTree(parentPid, (_, children) {
for (const { PID } of children) {
kill(PID);
}
kill(parentPid);
});
} |
But according to https://github.com/pkrumins/node-tree-kill/blob/master/index.js#L47-L56, it will kill child processes first. |
The logic you have referenced does not run for Windows: https://github.com/pkrumins/node-tree-kill/blob/3b5b8feeb3175a3e16ea7e0e09fdf5b8d2b87b08/index.js#L20-L21 |
Got it. So we can use 'terminate' instead, because it has the right killing order and you can refer to https://github.com/dwyl/terminate/blob/master/handlePsTreeCallback.js#L17 |
I have not used it yet, but if you want to use |
89ca646
to
66e5127
Compare
I'm done. |
I am verifying this on Windows. |
please don't forget to check licenses of new dependencies: https://github.com/theia-ide/theia/wiki/Registering-CQs#wip---new-ecd-theia-intellectual-property-clearance-approach-experimental |
I tried to verify it on Windows in the electron example app. It did not work. I did the followings:
|
@kittaakos Please try with node.js vscode extensions, they are in the better state.
|
+1 terminate is licensed under GPL v2.0 and so is not appropriate for an Eclipse Foundation project such as Theia. |
OK, I will refactor this PR without |
@kittaakos Please verify it again. |
@akosyakov, how can I make sure it is a fix for the leaking Java process? |
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>
I have tested with two vscode extensions: java 0.44.0 and java-debug 0.15.0 in Ubuntu and have the |
Thanks for the note, @tom-shan. Locally, I have rebased your code from the HEAD of Theia's |
If still have the same error, you can try with another repo which is much simpler and the debug session is started successfully. |
@kittaakos After the extra process of cleaning some data( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have verified it on Windows in electron. It worked. I started several Java debug processes, and when I refreshed the browser window, all Java processes were terminated. 👍 Thank you for your help on this, @tom-shan!
Are we good license-wise for this PR, @marcdumais-work? Thanks! |
LGTM - the latest version of this PR adds no new dependency ( |
Thank you for your help! |
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