-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Windows: child_process.spawn leaving orphaned processes around when running processes in an sh shell #34830
Comments
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)). |
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: edit2: |
I'm running in WSL and it has the same issue. The same code on osx behaves as expected. |
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? |
@nodejs/child_process |
@huseyinacacak-janea I'm no longer developing in Node on Windows. If you can't reproduce, feel free to close, thanks! |
Node.js v12 has reached its end of life and I wasn't able to reproduce it with the latest versions. |
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.
The text was updated successfully, but these errors were encountered: