Skip to content

fix: handle SIGINT/SIGTERM for graceful shutdown in Docker#74

Merged
rsbh merged 2 commits into
mainfrom
fix/signal-handling
May 15, 2026
Merged

fix: handle SIGINT/SIGTERM for graceful shutdown in Docker#74
rsbh merged 2 commits into
mainfrom
fix/signal-handling

Conversation

@rsbh
Copy link
Copy Markdown
Member

@rsbh rsbh commented May 15, 2026

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 --init flag or tini:

RUN apk add --no-cache tini
ENTRYPOINT ["/sbin/tini", "--"]

Test plan

  • chronicle dev — Ctrl+C stops the server
  • chronicle start — Ctrl+C stops the server
  • Docker container stops on docker stop (SIGTERM)

🤖 Generated with Claude Code

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>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chronicle Ready Ready Preview, Comment May 15, 2026 5:33am

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

Review Change Stack

Warning

Rate limit exceeded

@rsbh has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 36 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0d5dbbe6-619b-4ca4-b697-cc0e1570c01b

📥 Commits

Reviewing files that changed from the base of the PR and between 93e7d83 and d0235d9.

📒 Files selected for processing (2)
  • packages/chronicle/src/cli/commands/dev.ts
  • packages/chronicle/src/cli/commands/start.ts
📝 Walkthrough

Walkthrough

The PR adds graceful shutdown handlers to two CLI commands. The dev command registers a handler that closes the Vite server before exiting, while the start command registers a simpler handler that exits the process directly. Both commands now respond to SIGINT and SIGTERM signals with explicit shutdown logic instead of relying on default behavior.

Changes

Graceful shutdown handlers for CLI commands

Layer / File(s) Summary
Add graceful shutdown handlers to dev and start commands
packages/chronicle/src/cli/commands/start.ts, packages/chronicle/src/cli/commands/dev.ts
Both dev and start commands register signal handlers for SIGINT and SIGTERM. The dev command closes the Vite server before exiting; the start command exits directly with code 0.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding signal handlers for SIGINT/SIGTERM to enable graceful shutdown in Docker.
Description check ✅ Passed The description is directly related to the changeset, explaining the problem (Docker containers not stopping on Ctrl+C) and the solution (signal handlers in dev and start commands).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/signal-handling

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between eef9f1e and 93e7d83.

📒 Files selected for processing (2)
  • packages/chronicle/src/cli/commands/dev.ts
  • packages/chronicle/src/cli/commands/start.ts

Comment thread packages/chronicle/src/cli/commands/dev.ts Outdated
Comment thread packages/chronicle/src/cli/commands/start.ts Outdated
- 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>
@rsbh rsbh merged commit df3f1e3 into main May 15, 2026
4 checks passed
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