You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a mono-repo setup with multiple MFE apps including a host application. The host application uses the @nx/angular:module-federation-dev-server executor to launch the dev server, which builds all configured MFE projects before kicking off the host application.
Assuming the host application's project name is host, we would start the local server using the standard NX command syntax of:
nx run host:serve
This would generate output logs like this:
NX Starting module federation dev-server for <redacted> with 8 remotes
NX Building 8 static remotes...
Most of the time, the build completes as indicated by the message "NX Built 8 static remotes" and the server starts. However, we noticed that under random circumstances, especially when we force NX to skip cache via --skip-nx-cache, the build never completes and therefore the server never starts. I could reproduce the issue across my colleagues machines, although not 100% of the time. Sometimes nx run host:serve --skip-nx-cache would start the server just fine. A classic case of a race.
Fast forward to now, we identified the culprit for this hang. It has to do with how module-federation-dev-server waits for MFE project builds to finish. The server implementation forks a child process to run nx run-many -t build and waits for it to emit a certain string that indicates the build has finished successfully (i.e. Successfully ran target build). Only then does the enclosing Promise resolve, allowing next tasks to proceed until the dev server starts.
Now, when a child process exits "a little too early", its final stdout/stderr stream values could be discarded. What this entails is that the task would never complete, and this is exactly what we observed. See the following two screenshots that each represent a normal run and a run that will never resolve the Promise object.
(GOOD) A string whose presence is used to resolve the Promise is present before the child process exits
(BAD) The child process exits before it has a chance to print out its final output - Promise hangs indefinitely
Expected Behavior
Given the command nx run <host-app>:serve where uses the module-federation-dev-server executor for the serve target, the server should start successfully, with or without the --skip-nx-cache.
GitHub Repo
No response
Steps to Reproduce
Create one MFE host app and one remote app using @nx/angular:host and @nx/angular:remote.
Configure host's module-federation.config.ts to list the remote app in the remotes array.
Run the serve target on the host app.
If the server starts successfully, stop the server, repeat 3 but with --skip-nx-cache.
I discovered the issue originally on NX 18. Tried upgrading to NX 19 to experience the same issue (because the same gap is present in child process handling). The fix I will file soon is based on the latest master which is v19.
The text was updated successfully, but these errors were encountered:
…hild process exiting too early (#26684) (#26685)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->
<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->
<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->
## Current Behavior
See #26684
## Expected Behavior
See #26684Fixes#26684
---
This fix is targeted at NX 19. For a backport to NX 18, a small, trivial
change is necessary. I will file another PR targeting NX 18.
---------
Co-authored-by: Colum Ferry <[email protected]>
(cherry picked from commit 93b3e21)
Current Behavior
We have a mono-repo setup with multiple MFE apps including a host application. The host application uses the
@nx/angular:module-federation-dev-server
executor to launch the dev server, which builds all configured MFE projects before kicking off the host application.Assuming the host application's project name is
host
, we would start the local server using the standard NX command syntax of:This would generate output logs like this:
Most of the time, the build completes as indicated by the message "NX Built 8 static remotes" and the server starts. However, we noticed that under random circumstances, especially when we force NX to skip cache via
--skip-nx-cache
, the build never completes and therefore the server never starts. I could reproduce the issue across my colleagues machines, although not 100% of the time. Sometimesnx run host:serve --skip-nx-cache
would start the server just fine. A classic case of a race.Fast forward to now, we identified the culprit for this hang. It has to do with how
module-federation-dev-server
waits for MFE project builds to finish. The server implementation forks a child process to runnx run-many -t build
and waits for it to emit a certain string that indicates the build has finished successfully (i.e. Successfully ran target build). Only then does the enclosing Promise resolve, allowing next tasks to proceed until the dev server starts.Now, when a child process exits "a little too early", its final stdout/stderr stream values could be discarded. What this entails is that the task would never complete, and this is exactly what we observed. See the following two screenshots that each represent a normal run and a run that will never resolve the Promise object.
(GOOD) A string whose presence is used to resolve the Promise is present before the child process exits
(BAD) The child process exits before it has a chance to print out its final output - Promise hangs indefinitely
Expected Behavior
Given the command
nx run <host-app>:serve
where uses themodule-federation-dev-server
executor for the serve target, the server should start successfully, with or without the--skip-nx-cache
.GitHub Repo
No response
Steps to Reproduce
@nx/angular:host
and@nx/angular:remote
.module-federation.config.ts
to list the remote app in theremotes
array.serve
target on the host app.--skip-nx-cache
.Nx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
I discovered the issue originally on NX 18. Tried upgrading to NX 19 to experience the same issue (because the same gap is present in child process handling). The fix I will file soon is based on the latest master which is v19.
The text was updated successfully, but these errors were encountered: