Skip to content

fix: deregister the Forge tunnel when nx tunnel stops - #231

Merged
tbinna merged 1 commit into
betafrom
fix/tunnel-stop
Dec 1, 2026
Merged

tbinna merged 1 commit into
betafrom
fix/tunnel-stop

Conversation

@tbinna

@tbinna tbinna commented Nov 26, 2026

Copy link
Copy Markdown
Member

Summary

Pressing 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 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 remove options when 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=stream and 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.

  • Before (beta.3): Forge dies on SIGINT without sending a deregistration request.
    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).
Before After
Forge process same process group as Nx own process group
On Ctrl+C killed by SIGINT SIGTERM → deleteApplicationTunnels
Jira iframe source http://localhost:8000/… Forge CDN
Custom UI dev servers left running none none

Unit tests:

runTunnel
  ✓ starts the Forge CLI outside the terminal process group      (fails on beta)
  ✓ stops the Forge CLI only once                                (fails on beta)
remove uiKit2Packaging option
  ✓ removes the options of package targets that only set uiKit2Packaging
  ✓ keeps empty options that the migration did not change

nx run-many -t lint test -p nx-forge: lint is clean and 140 tests pass.

Merge Danger

Door: two-way

Blast Radius: tunnel

  • Only nx tunnel on macOS and Linux is affected. On Windows, forge tunnel is still stopped with taskkill.
  • Apps with a UI Kit resource (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 calls process.exit() before Forge deregisters. Plain forge tunnel plus kill -TERM shows the same thing.

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented Nov 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 004bce7f-c5ce-4b81-80f1-70e3b389bfd8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@tbinna
tbinna merged commit 2a696dc into beta Dec 1, 2026
6 checks passed
@tbinna
tbinna deleted the fix/tunnel-stop branch December 1, 2026 07:23
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 10.0.0-beta.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant