fix(gradle): destroy streams on exit to prevent daemon pipe hang#34705
Open
nimo71 wants to merge 1 commit intonrwl:masterfrom
Open
fix(gradle): destroy streams on exit to prevent daemon pipe hang#34705nimo71 wants to merge 1 commit intonrwl:masterfrom
nimo71 wants to merge 1 commit intonrwl:masterfrom
Conversation
✅ Deploy Preview for nx-docs canceled.
|
✅ Deploy Preview for nx-dev canceled.
|
When `execGradleAsync()` spawns Gradle via `execFile` with `shell: true`, the Gradle daemon inherits the shell's stdout/stderr pipe file descriptors. After the task completes, the daemon continues running and holds these pipes open, preventing the shell wrapper from exiting. Since Node.js resolves the `exit` event based on the shell process terminating, the Promise hangs indefinitely. Fix: Forcibly destroy stdout/stderr streams after the `exit` event fires. By this point all output has been buffered, so no data is lost. Destroying the streams releases the pipe FDs from Node's perspective, allowing the shell to exit and the Promise to resolve. Refs: nodejs/node#5637, gradle/gradle#3987
956a456 to
29adb96
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
execGradleAsync()inexec-gradle.tscan hang indefinitely during project graph creation. This manifests as Nx freezing on "Creating project graph nodes" — particularly in CI environments, but also reproducible locally.Expected Behavior
execGradleAsync()should resolve/reject promptly after the Gradle task completes, regardless of whether the Gradle daemon continues running in the background.Root Cause
execGradleAsync()usesexecFile()withshell: true, which spawns a shell wrapper process. The Gradle daemon, started bygradlew, inherits the shell's stdout/stderr pipe file descriptors. After thenxProjectGraphtask completes:gradlewwrapper script exitsexitevent on the child processexecGradleAsync()never resolvesThis is a well-documented interaction between:
execFilehangs when child exits but disowned children hold pipesFix
Destroy stdout/stderr streams immediately after the
exitevent fires. By this point, all output data has already been buffered into thestdoutvariable via thedataevent handlers, so no output is lost. Destroying the streams releases the pipe FDs from Node's perspective, allowing the shell wrapper to exit and the Promise to resolve — regardless of daemon state.Workarounds Users Currently Need
Without this fix, users must resort to:
org.gradle.daemon.idletimeout=5000ingradle.properties(adds 5s latency per invocation)timeout+pkill -f GradleDaemon(unreliable, wastes CI minutes)--no-daemonflag (doesn't work reliably with Gradle 8.1+/9.x — a "single-use daemon" is still forked whenorg.gradle.jvmargsis set)Related Issues
Creating project graph nodes with 7 plugins#32788 — CI hanging at "Creating project graph nodes"