Skip to content

fix: only register signal-exit handler when a trace subscriber is active - #11208

Merged
hyfdev merged 1 commit into
rolldown:mainfrom
DaniilIsupov:fix/signal-exit-only-with-trace-subscriber
Oct 16, 2026
Merged

hyfdev merged 1 commit into
rolldown:mainfrom
DaniilIsupov:fix/signal-exit-only-with-trace-subscriber

Conversation

@DaniilIsupov

@DaniilIsupov DaniilIsupov commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem

packages/rolldown/src/setup.ts calls onExit from signal-exit unconditionally on import:

const subscriberGuard = initTraceSubscriber();
onExit(() => { subscriberGuard?.close(); });

initTraceSubscriber() returns a guard only when chrome tracing is active (RD_LOG + RD_LOG_OUTPUT=chrome-json, which requires the chrome-tracing feature of a profile build). In release builds it is always null, so the handler never does anything. Every process that imports rolldown still gets SIGHUP/SIGINT/SIGTERM listeners.

On a signal, signal-exit removes its listeners and re-raises the signal with process.kill(process.pid, sig). With an inspector session attached (node --inspect + DevTools), Node goes into its exit path and blocks in inspector::Agent::WaitForDisconnect() instead of exiting. In practice, closing the terminal leaves the dev server orphaned (PPID 1) and still holding its ports, so the next start fails with EADDRINUSE. Vite 8 loads rolldown itself, so this affects any Vite-based dev server run under --inspect.

Reported downstream in vikejs/vike#3577 (see also vikejs/vike#3611, where the fix was suggested to live in rolldown).

Fix

Register the onExit handler only when a trace subscriber guard actually exists. The CLI's own onExit in cli/commands/bundle.ts is left untouched: it only runs in CLI watch mode, where the CLI owns the process.

Added tests/behaviors/no-signal-listeners-on-import.test.ts, which checks that importing rolldown with RD_LOG unset adds no SIGHUP/SIGINT/SIGTERM listeners.

Reproduction

app.mjs:

import 'rolldown';
console.log('SIGHUP listeners:', process.listenerCount('SIGHUP'));
setInterval(() => {}, 1000);

run.mjs spawns node --inspect=9339 app.mjs, connects an inspector client (/json/list → webSocketDebuggerUrl, sends Runtime.enable), then sends SIGHUP to the child.

Results (macOS, Node 24.21.0):

SIGHUP listeners After SIGHUP
[email protected] 1 Waiting for the debugger to disconnect..., process stays alive
[email protected] with this change applied to dist/index.mjs 0 process exits (signal=SIGHUP), inspector gets "target closed"

Without an attached debugger the process exits in both cases, so the inspector is required to reproduce this.

Note: I could not build the native binding locally (no Rust toolchain on this machine), so the new test has not been run locally. It relies on CI. The behavior change was verified by applying the same edit to the published dist.

AI disclosure

This PR was prepared with help from Claude Code (investigation, fix, repro, test, and this description). I reviewed the changes and the repro results.

🤖 Generated with Claude Code

@DaniilIsupov

Copy link
Copy Markdown
Contributor Author

The Vite Test Ubuntu failure is in the playground/assets/__tests__/assets.spec.ts build-watch tests ("import module.css", "import with raw query"): the rebuilt output still has the old content. This looks flaky and unrelated to this change; the same file also fails on other recent PRs (e.g. https://github.com/rolldown/rolldown/actions/runs/38502028949). Could someone with write access re-run it?

@DaniilIsupov
DaniilIsupov marked this pull request as ready for review October 14, 2026 09:10
@hyfdev

hyfdev commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Thank you! Will merge it after today's release

@DaniilIsupov

Copy link
Copy Markdown
Contributor Author

Thank you! Will merge it after today's release

Hi @hyfdev, friendly ping - v1.2.14 is out, could this be merged now? Happy to rebase onto the latest main if needed

@hyfdev
hyfdev enabled auto-merge (squash) October 16, 2026 14:48
`setup.ts` called `onExit` from `signal-exit` unconditionally on import, so
every process importing rolldown got SIGHUP/SIGINT/SIGTERM listeners even
though the trace subscriber guard is `null` unless chrome tracing is enabled.
`signal-exit` re-raises the signal after its handlers run, and with an
inspector attached (`node --inspect`) Node then waits for the debugger to
disconnect instead of exiting, leaving orphaned dev servers holding ports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@hyfdev
hyfdev force-pushed the fix/signal-exit-only-with-trace-subscriber branch from 9ab909b to 35b4739 Compare October 16, 2026 14:48
@netlify

netlify Bot commented Oct 16, 2026

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 35b4739
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6ad2393572f32ecff8f29139
😎 Deploy Preview https://deploy-preview-11208--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hyfdev
hyfdev merged commit 33a987d into rolldown:main Oct 16, 2026
34 checks passed
@rolldown-guard rolldown-guard Bot mentioned this pull request Oct 21, 2026
shulaoda added a commit that referenced this pull request Oct 21, 2026
## [1.2.15] - 2026-10-21

### 🚀 Features

- rolldown_plugin_vite_resolve: add `isBundled` to pick the browser-external stub format (#11260) by @h-a-n-a
- dev: mark entry modules in the HMR module graph (#11252) by @h-a-n-a
- mark module starts with `// <id>` comments instead of `#region` pairs (#11235) by @IWANABETHATGUY

### 🐛 Bug Fixes

- plugin: stop `this.resolve` recursion between plugins with `skipSelf: true` (#11181) by @anzal1
- rolldown_plugin_vite_resolve: handle external `require` for `ssr.target: 'webworker'` (#11205) by @sapphi-red
- rolldown_plugin_vite_build_import_analysis: only wrap dynamic imports with static specifiers in __vitePreload (#10879) by @smeng9
- strict-execution-order: wrap eager modules that forward wrapped definers (#11186) by @hyfdev
- chunk-import-map: keep common chunk keys unique when enabling inline common chunks (#11230) by @hyfdev
- only register signal-exit handler when a trace subscriber is active (#11208) by @DaniilIsupov

### 🧪 Testing

- fold hand-unrolled Rust test tables (#11212) by @Brooooooklyn

### ⚙️ Miscellaneous Tasks

- deps: upgrade oxc to 0.155.0 (#11228) by @Dunqing
- rollup-tests: retriage failed tests (#11251) by @sapphi-red
- deps: update rollup submodule for tests to v4.64.12 (#11249) by @rolldown-guard[bot]
- deps: update test262 submodule for tests (#11242) by @rolldown-guard[bot]

### ❤️ New Contributors

* @anzal1 made their first contribution in [#11181](#11181)
* @smeng9 made their first contribution in [#10879](#10879)
* @DaniilIsupov made their first contribution in [#11208](#11208)

Co-authored-by: shulaoda <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants