Skip to content

fix(rivetkit): exit pid1 after signal shutdown#5045

Draft
NathanFlurry wants to merge 1 commit into
active-actors/fix-active-countfrom
rivetkit-shutdown/exit-pid1-after-drain
Draft

fix(rivetkit): exit pid1 after signal shutdown#5045
NathanFlurry wants to merge 1 commit into
active-actors/fix-active-countfrom
rivetkit-shutdown/exit-pid1-after-drain

Conversation

@NathanFlurry
Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 12, 2026

Code Review

Overview

This PR fixes a well-known container issue: when Node.js runs as PID 1 (common in Docker containers), re-raising SIGINT/SIGTERM with process.kill(process.pid, signal) can be swallowed by the kernel because PID 1 has no default signal disposition unless explicitly set. The fix detects PID 1 and calls process.exit() with the POSIX-conventional exit code instead.

What's good

  • Correct exit codes. 130 (128+SIGINT=2) and 143 (128+SIGTERM=15) are the de-facto Unix convention for signal-terminated exits. Container runtimes and orchestrators (Kubernetes, ECS) interpret these correctly.
  • Exhaustive switch. signalExitCode covers both ShutdownSignal variants explicitly with no _ fallthrough — consistent with the project's enum-matching convention.
  • Minimal scope. The fix is surgical: two call sites replaced, one helper added, zero changes to shutdown sequencing logic.
  • Comment quality. The inline comment on the second-delivery path explains why the behaviour changed, not what the code does, which is exactly the right bar.

Minor observations

  1. process.pid check is reliable. In Linux PID namespaces (the common Docker case), the init process always sees itself as PID 1. Outside a PID namespace (e.g., --pid=host), it won't be PID 1 and the original process.kill path fires correctly. Logic is sound.

  2. PR checklist is empty. The description template boxes are all unchecked. Not a blocker for this focused fix, but worth capturing how this was manually verified (e.g., a docker run --init=false smoke test).

  3. No automated test coverage. PID 1 behaviour is difficult to unit-test without a real container. A follow-up integration test in the existing platform smoke-test harness (packages/rivetkit/tests/platforms/) would be useful if one doesn't exist.

Verdict

The fix is correct, minimal, and follows project conventions. Ready to merge once promoted from draft and the manual verification story is captured.

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.

1 participant