GeezerVison is showing github.com — Windows: child_process.spawn leaving orphaned processes around when running processes in an sh shell · Issue #34830 · nodejs/node
Windows: child_process.spawn leaving orphaned processes around when running processes in an sh shell #34830Labels child_processIssues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform. Description
- Version: 12.14.1
- Platform: Windows 10
- Subsystem: x64 1909
What steps will reproduce the bug?
Please see this reproduction utility & its readme:
https://github.com/ManiacDC/npm-sh-issue
Basically, launching node from an sh shell, then running tsc from a new shell (sh -c) from within node, will leave orphaned processes behind when ctrl-c is hit in the terminal.
For reference, stdio is set to pipe, windowsHide is set to false, and shell is set to true. If stdio is set to 'inherit', this issue does not occur.
How often does it reproduce? Is there a required condition?
On demand. stdio must NOT be set to inherit. The shell launching node must be "sh" or "bash", the shell being used to launch tsc must be "sh" or "bash".
What is the expected behavior?
All child processes should close.
What do you see instead?
The child processes are orphaned and remain running until killed in the task manager (since they run tsc -w, which runs until terminated).
Additional information
This was originally discovered via lerna/lerna#2284 , reported on sindresorhus/execa#433, and narrowed down to this. I think this may actually be an issue with git-for-windows/msys2's implementation of sh & bash, but I'm not sure. Reacted by Justin Chase, Sindre Sorhus, ehmicky, Mortifia, Sean Blonien, Josh Kellendonk, Florian Guitton, John Rosewicz, Ali Ashraf (OMO) and Daniel Santos Activitybzoz commented on Aug 19, 2020 It might be that npm waits for your pipes to be closed. You can try something like this we used to fix calling npm from CITGM: nodejs/citgm@595dcf6
Anyway, there are a lot of moving parts here. It is possible that there is a Node bug here, or bash incorrectly sets up pipes or maybe npm is doing something off. Could you try to boil it down to something that at least does not include npm? A perfect reproducible example would only use your Node.js code, without npm and without tsc which also could introduce this.
My guess is that when you do all this shell switcheroos npm ends up not using winpty (#14100 (comment)). ManiacDC commented on Aug 19, 2020 Yes, it's not using winpty, but that's out of my control as this is being launched from a cross-platform shell script - which won't be using winpty. Also, how node launches the npm script is somewhat out of my control (this is being launched from within lerna in my original issue).
The original example was a shell script launching lerna via npx to call npm scripts. I was able to get rid of the npx and lerna parts, but that's it.
edit1:
I figured out a way to remove npm from the picture - check the reproduction repo... tsc is still involved, but I'm just using that as a looping process and it exits normally in other situations.
edit2:
I also found a way to remove tsc. I added a second reproduction method using "sleep", instructions in readme. If sleep is launched directly from node, or even via "sh -c 'tsc -w'" from node - this issue does not happen. I had to launch it from within a script to get it to happen. changed the title [-]Windows: child_process.spawn leaving orphaned processes around when running npm scripts in an sh shell[/-] [+]Windows: child_process.spawn leaving orphaned processes around when running processes in an sh shell[/+] on Aug 19, 2020justinmchase commented on Aug 21, 2020 I'm running in WSL and it has the same issue. The same code on osx behaves as expected. huseyinacacak-janea commented on May 2, 2024 Hi @ManiacDC, I wanted to look into this issue but wasn't able to reproduce it (I tried Node 18.20.2, 20.12.2, and 22.0.0). Do you think this can be closed now? avivkeller commented on May 4, 2024 ManiacDC commented on May 5, 2024 @huseyinacacak-janea I'm no longer developing in Node on Windows. If you can't reproduce, feel free to close, thanks! huseyinacacak-janea commented on May 8, 2024 Node.js v12 has reached its end of life and I wasn't able to reproduce it with the latest versions.
@redyetidev, @ManiacDC I don't have the right to close the issue. Can one of you please close it?
MetadataMetadatachild_processIssues and PRs related to the child_process subsystem.windowsIssues and PRs related to the Windows platform. DevelopmentNo branches or pull requestsIssue actions
|