-
Notifications
You must be signed in to change notification settings - Fork 29.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
Terminal leaks processes #26807
Comments
This also affects the task runner when using the terminal as the execution engine |
Executing this natively in a PowerShell command prompt and using Ctrl+C to interrupt the process works as expected. |
Using node version 6.5.0 but happens with 7.10.0 for me as well. |
I just noticed that this also happens in Hyper.js. Looks like something has changed how winpty-agent launches processes. |
Related: #26897 |
I actually can't reproduce using your steps on:
I tried 3 times and every time both node and conhost processes are terminated after around 5 seconds max which is consistent with the code https://github.com/Microsoft/vscode/blob/f95866f07eaf1cdea610479a11778ae82f69bf4b/src/vs/workbench/parts/terminal/node/terminalProcess.ts#L129 Any more info on a repro would be good. What version of Windows are you on? |
I will see if I can find out more. However I do see them leak and I was even able to reproduce the leaking in Hyper.js. How does winpty-agent start the process. Is it using detach ? |
And from using processes in tasks heavily I know that if a sub process inherits the input/output stream from a parent parent process then the child process might get orphaned if the streams are still open. So in the case of VS Code -> winpty -> node it might happend that node inherits stdio from VS Code and when winpty gets killed node is still sticking around since the stream owned be VS Code are still around. |
I believe it works like this: VS Code (node-pty) -> winpty-agent -> conhost -> node Just speculating here, but maybe we need to tell ptyProcess to die here: https://github.com/Microsoft/vscode/blob/66bc0d13fafadbddb5b26a3bc114bdcc29cfd39c/src/vs/workbench/parts/terminal/node/terminalProcess.ts#L127 |
Something similar happens when doing the same in a regular cmd.exe window, you need to hit the X window button about 4 times though as it only kills 2 or so of the processes at once. It eventually kills them all though if you're persistent. |
I can kill all the processes forcefully by running this:
Not sure that's better though. |
@rprichard do you know why some processes running in the shell on Windows (servers in particular) don't get killed but all other processes in the tree are? |
@dbaeumer Thanks for the test case. I was able to immediately reproduce the issue. Some background:
When I run I found the problem on GitHub by searching for case CTRL_CLOSE_EVENT:
if (uv__signal_dispatch(SIGHUP)) {
/* Windows will terminate the process after the control handler */
/* returns. After that it will just terminate our process. Therefore */
/* block the signal handler so the main loop has some time to pick */
/* up the signal and do something for a few seconds. */
Sleep(INFINITE);
return TRUE;
}
return FALSE; When I click the 'X' button of a console with When I click the 'X' button a second time, I guess Windows knows that the console ctrl handler is already running and decides to just kill the thing. Two ideas for a fix:
Right now, I lean towards fix 2 because it seems like less trouble. I'm not sure about the VSCode "plan B" thing. As long as it doesn't terminate (Note to self: I wonder what happens if I register a new console ctrl handler between the two |
I suppose leaving Actually, this seems like an argument for implementing fix 1, if that's feasible. |
Created rprichard/winpty#129 in winpty. |
@dbaeumer unfortunately I'm busy through September with Electron tasks and travel so I doubt I'll be able to get to this. I'm committed to making it a priority and explicitly putting it on the October iteration plan though. |
@the-ress did you end up making any progress on your branch of node-pty? If it's still a WIP maybe I can take what you have when I free up and build upon it? |
@Tyriar thanks for letting me know. |
@Tyriar no, it's still WIP/PoC. Yes, of course you can. |
Created rprichard/winpty#130 with winpty part of the changes. |
@the-ress just tested your winpty patch and it correctly returns the process list without the notepad process launched via |
I am experiencing this issue on win 10 x64.
node.exe gets orphaned when using Tested with git bash and ps as terminal. |
@edongashi the fix for this will be out in v1.18, you can try it out now in the Insiders build https://code.visualstudio.com/insiders |
Tried it. It's working as expected. Thanks! |
For me this is still occurring on for version 1.18 on Windows 10 with node js. If I kill the terminal using the garbage bin button the node processes are killed correctly. If VS Code is closed the processes keep running. |
@Beretta1979 I am on Windows 10 and VS Code 1.18.0 and the integrated terminal I am using is |
@TomasHubelbauer I tested this both with terminal.integrated.shell.windows set to powershell (default) as with cmd.exe |
Steps to Reproduce:
Open a process explorer
Observe: there are still two process orphaned conhost.exe and node.exe
The text was updated successfully, but these errors were encountered: