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
Orphaned child processes keep running when exiting lerna run
with an error
#2284
Comments
Seems like we should be using signal-exit somewhere in |
Then again, So I'm kinda stumped. |
Do you know if detached can ever be true from the cli? It seems like if its not detached then this should not be possible or its a lower level, nodejs issue. |
No, we never set |
Are you able to reproduce it from the explanation or should I attach some code? I wonder if npm is itself spawning a detached process... |
I don't use |
Just an FYI, we are having the same issue with Lerna 3.20. I don't know how too recreate, but if things slow down I will try to troubleshoot. |
Same issue seen here
|
I'm seeing this issue with a process that detects interrupt signals and requires confirmation to exit. The process continues to run until it completes, but lerna exits immediately. It seems like these signals should be sent to child processes for them to handle. (In my case I am running the command with a single package scope, no parallel commands, so there's no risk of some sort of partial interrupt.) |
That matches what I was seeing also, I had code in there to handle |
I've dug into this pretty deeply and I have a simple reproduction finally, the issue linked above has all of the steps but there is one extra for Lerna: Follow the Steps here: Including uncommenting the line of code to call Observe in the browser that network requests continue successfully while the process should be shut down entirely. Restarting Lerna with So the process chain is something like:
The bottom most node process becomes orphaned when it doesn't shut down after receiving the SIGTERM signal from tsc-watch and then later when lerna is killed it doesn't ensure that all child processes are also shut down. |
We just ran into this and have figured out the conditions for reproducing:
This is a major roadblock to our team's work as we have people running on multiple platforms and are trying to standardize our npm scripts to all run in bash. |
This is definitely an issue with execa. I was able to reproduce this with both 1.0.0 and 4.0.2 in a standalone program. It may or may not be related to the issue I linked earlier. |
I have submitted a new execa issue for this: When this is fixed, this will likely require that lerna update to a newer version of execa. |
@evocateur please take a look at sindresorhus/execa#433 when you get a chance. Looks like there are some options for this. |
Is there some workaround for this in the meanwhile, based on sindresorhus/execa#433? |
Our workaround was to NOT change NPM's script-shell, leaving it at the platform default. Then we change incompatible scripts on an as-needed basis using "bash -c '<script here>'" and pray we don't run into issues. |
In the latest version of lerna I've been having success using WSL and in my npm start script I'm doing something like: {
"scripts": {
"start": "./start.sh"
}
} Then in the start script I'm using a trap to kill child processes: #!/bin/bash
# start.sh
onexit() {
for p in "${pids[@]}" ; do
kill "$p";
done
}
# Lerna sends a signal which the trap receives
trap onexit EXIT
pids=()
# Run as child processes
example &
pids+=($!)
# ...
# Wait for all child processes to exit
wait |
I see. Was hoping there was some solution without WSL/Bash :\ |
Can you please share the full script? I don't understand how you call the "lerna run --scope=packageName --parallel start" command. |
Oh sorry, in the root directory I have a package.json there, something like: {
"scripts": {
"start": "lerna run --parallel start"
},
"dependencies": {
"lerna": "...",
}
} Then the standard lerna package structure:
Also I refined this a little so you don't need to accumulate the pids manually with this: #!/bin/bash
function onclose()
{
for pid in $(jobs -p)
do
kill -9 ${pid} 2>/dev/null || echo -e ""
wait ${pid} 2>/dev/null
done
}
trap "onclose" INT TERM EXIT
examplea &
exampleb &
examplec & |
Yeah sorry there is probably a similar solution for non-bash, where you defer to a scripting language of your choice and then trap exit events and then close child processes explicitly. Thats the idea. Here is how you would attach to the exiting event in Powershell for example: Also, maybe this isn't the advice you're looking for but I basically just gave up on non-bash scripting environments and decided to just always use bash from now, even on windows, and its an enormously simplifying move. Easier said than done in old code bases but I try to refactor them as soon as possible to get away from it. If you're reluctant and you're telling yourself "but bash sucks!"... Yes, you're right it does suck :) But they all suck, really badly. It doesn't matter. What sucks the least is one sucky shell script rather than more than one. So I just gave in and picked the one that was the most portable. |
Ah :/ Thanks for the suggestion though. |
Is this getting solved? Facing the same issue using Windows + MINGW64 |
@magalhas This is likely not getting solved. Lerna is an abandoned project. |
I saw this issue's fix PR has been merged but not released, when is the next release, BTW last release was 7 months ago :| |
We tested this version with our repository and it caused other issues of the process continually respanwning. Downgrading to Lerna 3.22.1 seems to fix this issue. For now anyone who wants to use Lerna in a Windows environment should probably lock their dependency to that version. |
Confirmed. Downgrading to 3.22.1 resolved this issue regarding the hanging child processes. Thanks! |
Was stuck on this for 4 hours. Express server kept giving EADDRINUSE errors since Lerna wasn't terminating the Node server child processes...3.22.1 downgrade has resolved this |
I'm using Reverting to 3.22.1 also fixed it for me. Shame this is not fixed. What are the alternatives to Lerna if it's no longer maintained? |
same issue here, windows 10, lerna 4.0.0, parallel. |
any update? facing the issue on windows 11 with lerna 4.0.0 |
…orphaned processes are left. See lerna/lerna#2284
Yep, replicated with Windows 11 and lerna v4.0.0. Just with |
I'm guessing this repo has gone dark essentially in favor of the built-in "workspaces" feature in npm now: |
Same here, I'm also having this issue with Windows 10 or 11 and Lerna v4.0.0. |
Same here, considering Lerna is changing hands, maybe we can revive this issue @nrwl ? |
Thanks all! This should hopefully be fixed by @feryardiant change, applied in #3156 |
We waited literally 3 years for that 1 line fix 🤣 |
I'm running the command
lerna run --stream --parallel start
and if one of the apps has an error the others can be left running even as the lerna process exits.Expected Behavior
I expect all child processes to be killed when lerna exits.
Current Behavior
Lerna orphans processes
Possible Solution
I'm not familiar enough with the code :(
Steps to Reproduce (for bugs)
exit 1
in the "start" script in package.jsonlerna run --stream --parallel start
The fact that the nodejs app starts fine but the other app exits is causing the node.exe process to be orphaned.
Context
I just want to call
npm start
and have it start multiple apps in my mono repo. Then pressCtrl+C
to stop them all, repeat.Your Environment
I am running on windows, I have seen this behavior in both WSL and git bash. One of my apps just has
docker-compose up
as the script which starts up some containers like my db. If docker isn't running then this crashes for this reason. Also my app runs ngrok which also becomes orphaned.lerna --version
npm --version
yarn --version
node --version
The text was updated successfully, but these errors were encountered: