lerna: Orphaned child processes keep running when exiting `lerna run` with an error
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)
- Create the default project
- Create two apps, one is a simple nodejs express app, the other try
exit 1
in the “start” script in package.json lerna 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.
{
"packages": [
"apps/**"
],
"version": "0.0.0"
}
Context
I just want to call npm start
and have it start multiple apps in my mono repo. Then press Ctrl+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.
Executable | Version |
---|---|
lerna --version |
3.15.0 |
npm --version |
6.10.2 |
yarn --version |
N/A |
node --version |
v12.8.0 |
OS | Version |
---|---|
Windows 10 Pro | 1903 |
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 19
- Comments: 38 (5 by maintainers)
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.
any update? facing the issue on windows 11 with lerna 4.0.0
I’m using
lerna run --parallel dev
to run a local nodejs dev server and vite in GitBash windows. The problem for me what that vite was never killed and continued to block the TCP port.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?
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: https://github.com/apollographql/apollo-server/issues/4097
Including uncommenting the line of code to call
await stop()
. Once the server restarts the child process becomes orphaned, then doctrl+c
in your terminal to kill Lerna .Observe in the browser that network requests continue successfully while the process should be shut down entirely.
Restarting Lerna with
npm start
causes everything to startup fine but no network requests are recieved, a background orphaned process is receiving them. If you change the behavior of the code at all, the results of the network requests appear unchanged.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 waited literally 3 years for that 1 line fix 🤣
@magalhas This is likely not getting solved. Lerna is an abandoned project.
Thanks all!
This should hopefully be fixed by @feryardiant change, applied in https://github.com/lerna/lerna/pull/3156
Same here, considering Lerna is changing hands, maybe we can revive this issue @Nrwl ?
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
Is this getting solved? Facing the same issue using Windows + MINGW64
I see. Was hoping there was some solution without WSL/Bash :\
@evocateur please take a look at sindresorhus/execa#433 when you get a chance. Looks like there are some options for this.
I’m guessing this repo has gone dark essentially in favor of the built-in “workspaces” feature in npm now:
https://docs.npmjs.com/cli/v8/using-npm/workspaces
same issue here, windows 10, lerna 4.0.0, parallel.
In the latest version of lerna I’ve been having success using WSL and in my npm start script I’m doing something like:
Then in the start script I’m using a trap to kill child processes:
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.
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.
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.