Repository navigation
fix: deregister the Forge tunnel when nx tunnel stops - #231
Merged
Merged
Conversation
Ctrl+C on nx tunnel left the Forge tunnel registered, so Jira kept loading the app from localhost. Under Nx, the output of forge tunnel is not a terminal, so the Forge CLI does not read Ctrl+C as a key press. The terminal sent SIGINT to its whole process group instead, and the Forge CLI exited without deregistering. Start forge tunnel in its own process group on POSIX systems, so that only the executor gets the SIGINT and stops the Forge CLI with SIGTERM. Also stop the Forge CLI only once. The executor stopped it on a termination signal and again when another started process failed. The second SIGTERM made the Forge CLI exit before it deregistered. The 10.0.0 option migrations now also remove options that end up empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Contributor
|
🎉 This PR is included in version 10.0.0-beta.4 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
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.
Summary
Pressing Ctrl+C on
nx tunnelleft the Forge tunnel registered, so Jira kept loading the app fromlocalhost.Under Nx, the output of
forge tunnelis not a terminal, so the Forge CLI doesn't read Ctrl+C as a key press. The terminal sent SIGINT to its whole process group, and Forge exited without deregistering.Ctrl+C terminal → SIGINT to the foreground process group nx, run-executor - forge tunnel → exits, tunnel stays registered + run-executor → SIGTERM once → forge tunnel deregisters + (forge tunnel runs in its own process group on POSIX)runTunnel spawnForgeCommand(['tunnel'], { + detached: process.platform !== 'win32', }) - forwardTerminationSignals(tunnelProcess) // SIGTERM per signal - signal.on('abort', () => stopProcessTree(...)) // and again on abort + stopTunnel = once(() => stopProcessTree(tunnelProcess)) + forwardTerminationSignals(tunnelProcess, stopTunnel) + signal.on('abort', stopTunnel)Forge also had to be stopped only once. The executor sent SIGTERM on a termination signal and sent it again when another started process failed. Forge's cleanup isn't idempotent, so the second SIGTERM made it exit before it deregistered ("Tunnel cleanup failed: Server is not running.").
The 10.0.0 option migrations (
tsConfig,uiKit2Packaging) now removeoptionswhen they end up empty. Empty named configurations stay, because tasks can still run them by name.Evidence
I tested against nx-forge-examples (Nx 24.0.7, Forge CLI 16.0.0) with
nx tunnel nx-forge-app-webpack --output-style=streamand Ctrl+C in a pseudo-terminal. To see where Jira loaded the app from, I read the iframe source on the app's global page.After: Forge gets SIGTERM and sends the deregistration request. Jira loads the app from the CDN again (3 of 3 runs, one of them a closed terminal, i.e. SIGHUP).
deleteApplicationTunnelshttp://localhost:8000/…Unit tests:
nx run-many -t lint test -p nx-forge: lint is clean and 140 tests pass.Merge Danger
Door: two-way
Blast Radius: tunnel
nx tunnelon macOS and Linux is affected. On Windows,forge tunnelis still stopped withtaskkill.render: native) still stay registered after Ctrl+C. This is a Forge CLI bug outside nx-forge: its UI Kit tunnel server, a webpack-dev-server, handles SIGTERM itself and callsprocess.exit()before Forge deregisters. Plainforge tunnelpluskill -TERMshows the same thing.🤖 Generated with Claude Code