Skip to content

fix(core): call process.exit(0) after successful build and index commands#34453

Closed
mixelburg wants to merge 1 commit into
storybookjs:mainfrom
mixelburg:fix/build-exit-on-complete
Closed

fix(core): call process.exit(0) after successful build and index commands#34453
mixelburg wants to merge 1 commit into
storybookjs:mainfrom
mixelburg:fix/build-exit-on-complete

Conversation

@mixelburg
Copy link
Copy Markdown

@mixelburg mixelburg commented Apr 2, 2026

Summary

Fixes #34446

The build and index commands in code/core/src/bin/core.ts log success but never call process.exit(0). With Vite/chokidar and other tools that register file watchers or keep-alive handles, the Node.js process hangs indefinitely after the build completes—it only exits when those handles eventually time out or are garbage collected.

The error path already calls process.exit(1), so adding process.exit(0) to the success path is the consistent fix. This matches the pattern used by the CLI's dev wrapper (which also exits with 0 on success).

Changes

  • command('build'): add process.exit(0) after logger.outro('Storybook build completed successfully')
  • command('index'): add process.exit(0) after the awaited index call

Summary by CodeRabbit

  • Bug Fixes
    • The build and index commands now properly terminate upon successful completion.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

Added explicit process.exit(0) calls to the build and index commands to immediately terminate the Node.js process after successful completion, replacing reliance on default event-loop behavior. Error handling paths remain unchanged.

Changes

Cohort / File(s) Summary
Process Termination
code/core/src/bin/core.ts
Added explicit process.exit(0) calls after successful completion of build and index commands to ensure immediate process termination.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes


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

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/bin/core.ts`:
- Line 192: The build and index command action handlers currently call
process.exit(0) which kills the process before the postAction hook (postAction)
can persist logs; remove those direct process.exit(0) calls and replace them by
invoking a centralized success handler (e.g., handleSuccess or finalizeAndExit)
that runs the same log-writing/persistence logic currently in postAction (ensure
it triggers or awaits postAction's file-write code) and only then calls
process.exit(0); update the build and index action handlers to call this success
handler instead of exiting directly so logfile writing completes on successful
runs.
🪄 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: 8d030d5d-5e52-49a2-a429-bed155e2e567

📥 Commits

Reviewing files that changed from the base of the PR and between e085c39 and 508a095.

📒 Files selected for processing (1)
  • code/core/src/bin/core.ts

Comment thread code/core/src/bin/core.ts
});

logger.outro('Storybook build completed successfully');
process.exit(0);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the lifecycle conflict and affected paths in the reviewed file.
rg -n -C3 "hook\\('postAction'|writeToFile\\(|command\\('build'\\)|command\\('index'\\)|process\\.exit\\(0\\)" code/core/src/bin/core.ts

Repository: storybookjs/storybook

Length of output: 1625


process.exit(0) inside action handlers prevents postAction hook from writing debug logs

At Line 192 (build command) and Line 220 (index command), process.exit(0) terminates the process before the postAction hook (Line 73) can execute. This prevents the log file persistence logic at Line 76 from running on successful completion, causing debug logs to be lost for users with --logfile enabled.

Move log writing and exit handling into a dedicated success handler:

Suggested fix
 const handleCommandFailure = async (logFilePath: string | boolean): Promise<never> => {
   try {
     const logFile = await logTracker.writeToFile(logFilePath);
     logger.log(`Debug logs are written to: ${logFile}`);
   } catch {}
   logger.outro('Storybook exited with an error');
   process.exit(1);
 };
+
+const handleCommandSuccess = async (logFilePath: string | boolean): Promise<never> => {
+  if (logTracker.shouldWriteLogsToFile) {
+    try {
+      const logFile = await logTracker.writeToFile(logFilePath);
+      logger.outro(`Debug logs are written to: ${logFile}`);
+    } catch {}
+  }
+  process.exit(0);
+};
@@
     logger.outro('Storybook build completed successfully');
-    process.exit(0);
+    await handleCommandSuccess(options.logfile);
   });
@@
-    process.exit(0);
+    await handleCommandSuccess(options.logfile);
   });

Also applies to: Line 220

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/bin/core.ts` at line 192, The build and index command action
handlers currently call process.exit(0) which kills the process before the
postAction hook (postAction) can persist logs; remove those direct
process.exit(0) calls and replace them by invoking a centralized success handler
(e.g., handleSuccess or finalizeAndExit) that runs the same
log-writing/persistence logic currently in postAction (ensure it triggers or
awaits postAction's file-write code) and only then calls process.exit(0); update
the build and index action handlers to call this success handler instead of
exiting directly so logfile writing completes on successful runs.

@valentinpalkovic
Copy link
Copy Markdown
Contributor

Hi @mixelburg,

Thank you for your contribution so far.

Your contributions so far seem purely AI-driven without any manual verification. I've gently asked for verification in some of your recent PRs. Please don't create new PRs while the old ones are still open. The Storybook team accepts PRs that are AI-generated, but only if the work is well understood and verified by the PR creator. If these requirements aren't met, I will start auto-closing PRs that don't have a human contribution, such as at least manual validation of the work. Also, please use your PR template in the future when creating PRs. I'll close this and any future PRs unless the requested validation for the recent ones is provided. I'll also autoclose the older PRs soon, if I don't hear back from you within the next couple of working days, assuming that I'm not talking to a human.

Thank you for your understanding!

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