Skip to content

Core: Ensure process termination on SIGINT when telemetry is disabled#34585

Merged
ghengeveld merged 1 commit into
nextfrom
fix-sigint-handling
Apr 17, 2026
Merged

Core: Ensure process termination on SIGINT when telemetry is disabled#34585
ghengeveld merged 1 commit into
nextfrom
fix-sigint-handling

Conversation

@ghengeveld
Copy link
Copy Markdown
Member

@ghengeveld ghengeveld commented Apr 17, 2026

What I did

Storybook was leaving behind lingering Node.js processes after being terminated, but only when telemetry was disabled. This PR fixes that bug.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Start Storybook with telemetry disabled. Kill it (Cmd+C), then use Activity Monitor to verify no node processes are left behind.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Bug Fixes
    • Improved development server shutdown reliability to ensure proper termination regardless of telemetry module state.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 17, 2026

View your CI Pipeline Execution ↗ for commit 1d5f0b7

Command Status Duration Result
nx run-many -t compile,check,knip,test,lint,fmt... ✅ Succeeded 11m 56s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-17 10:06:20 UTC

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a dev-server shutdown bug where Storybook could leave the Node.js process running after SIGINT/SIGTERM when telemetry is disabled, by ensuring the signal handler always terminates the process.

Changes:

  • Refactors the cancelTelemetry signal handler so process.exit(0) runs in a finally block.
  • Keeps sending the canceled telemetry event (with story index/stats) when telemetry is enabled, but still exits when it’s disabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 17, 2026

📝 Walkthrough

Walkthrough

The cancelTelemetry signal handler in the dev server was restructured to guarantee process termination by moving process.exit(0) into a finally block, ensuring exit occurs regardless of telemetry module state.

Changes

Cohort / File(s) Summary
Signal Handler Restructuring
code/core/src/core-server/dev-server.ts
Modified cancelTelemetry signal handler to relocate telemetry payload construction to execute only when telemetry is enabled, move cancellation logic inside the enabled branch, and guarantee process termination via finally block regardless of telemetry module state.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/core/src/core-server/dev-server.ts`:
- Around line 211-223: The signal shutdown currently awaits potentially-hung
operations (storyIndexGeneratorPromise / generator.getIndexAndStats() and
telemetry(...)), so change both awaits to bounded best-effort waits: wrap
awaiting storyIndexGeneratorPromise and generator.getIndexAndStats() in a
Promise.race with a small timeout (e.g., 200–500ms) so missing index data is
skipped if slow, and call telemetry('canceled', payload, { immediate: true })
via a Promise.race with a short timeout (or fire-and-forget while still
attempting a short await) to ensure the signal handler does not block
indefinitely; update references to storyIndexGeneratorPromise, getIndexAndStats,
summarizeIndex, and telemetry accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f0a0e4cb-9196-437b-a684-4289bc756925

📥 Commits

Reviewing files that changed from the base of the PR and between 09fb0ba and 1d5f0b7.

📒 Files selected for processing (1)
  • code/core/src/core-server/dev-server.ts

Comment thread code/core/src/core-server/dev-server.ts
@ghengeveld ghengeveld merged commit 5266690 into next Apr 17, 2026
129 of 133 checks passed
@ghengeveld ghengeveld deleted the fix-sigint-handling branch April 17, 2026 11:15
@github-actions github-actions Bot mentioned this pull request Apr 17, 2026
16 tasks
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.

3 participants