fix: handle SIGINT/SIGTERM for graceful shutdown in Docker#74
Conversation
Dev and start commands now close Vite server and exit on SIGINT/SIGTERM. Fixes Docker container not stopping on Ctrl+C. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe PR adds graceful shutdown handlers to two CLI commands. The ChangesGraceful shutdown handlers for CLI commands
🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/chronicle/src/cli/commands/dev.ts`:
- Around line 32-37: Make the dev shutdown idempotent and error-safe by
replacing process.on('SIGINT'|'SIGTERM', shutdown) with process.once so the
handler runs only once, add a module-scoped boolean flag (e.g., shuttingDown)
checked at the top of the shutdown function to guard re-entrance, and wrap the
await server.close() call inside a try/catch; on success call process.exit(0),
and on failure log the error and call process.exit(1) to ensure non-zero exit
codes on errors while preventing concurrent close calls in shutdown().
In `@packages/chronicle/src/cli/commands/start.ts`:
- Around line 30-32: The current shutdown handler calls process.exit(0)
immediately which prevents the Vite PreviewServer from being closed; update the
shutdown logic (the shutdown function and the process.on('SIGINT'/'SIGTERM')
handlers) to be async and await the PreviewServer.close() call (use the
PreviewServer instance, e.g., previewServer.close()) before exiting, handle/ log
any errors from close(), and ensure shutdown is idempotent (guard against
multiple invocations) so the server is properly cleaned up before calling
process.exit(0).
🪄 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: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1bb05076-094b-4236-a2fc-e00b40e1d5b5
📒 Files selected for processing (2)
packages/chronicle/src/cli/commands/dev.tspackages/chronicle/src/cli/commands/start.ts
- process.once instead of process.on to prevent double-fire - shuttingDown flag guards re-entrance - try/catch around server.close() to handle errors - start command now calls server.close() before exit Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Dev and start commands now handle SIGINT/SIGTERM signals to gracefully close the Vite server and exit. Fixes Docker container not stopping on Ctrl+C.
For Docker, also recommend using
--initflag or tini:Test plan
chronicle dev— Ctrl+C stops the serverchronicle start— Ctrl+C stops the serverdocker stop(SIGTERM)🤖 Generated with Claude Code