Skip to content

fix(runtime): handle SIGTERM for graceful shutdown (#2519)#2520

Merged
devarismeroxa merged 1 commit into
mainfrom
fix/2519-sigterm-graceful-shutdown
Jul 4, 2026
Merged

fix(runtime): handle SIGTERM for graceful shutdown (#2519)#2520
devarismeroxa merged 1 commit into
mainfrom
fix/2519-sigterm-graceful-shutdown

Conversation

@devarismeroxa

Copy link
Copy Markdown
Contributor

Closes #2519. Tier 1 (data path) — requires human sign-off + failure-mode analysis.

Problem

CancelOnInterrupt (entrypoint.go) registered only os.Interrupt (SIGINT). SIGTERM — sent by docker stop, kubectl delete pod, and systemctl stop — was never caught, so it hit Go's default disposition: immediate process death, no drain. Pipelines were not checkpointed and in-flight records not drained, violating data-integrity invariant 7.

Fix

Register syscall.SIGTERM alongside os.Interrupt so SIGTERM drives the same graceful path SIGINT already drives (first signal → cancel root ctx → StopAll drains up to exitTimeout; second signal → hard exit). After this change SIGTERM behaves exactly as SIGINT does today. One-line signal registration + docs.

Design doc

docs/design-documents/20260704-graceful-shutdown-sigterm.md (problem, constraints, alternatives, failure modes, upgrade/rollback, observability, explicit scope boundary).

Failure-mode analysis (Tier 1)

  • What could this break? It only adds a caught signal; it changes no shutdown logic. SIGINT behavior is untouched (same signal.Notify call, same goroutine). Risk surface is minimal.
  • Drain exceeds exitTimeout (30s): existing wait escalates to forced stop then exits; un-drained work recovered on restart via at-least-once + crash-safe positions. Unchanged from today's SIGINT path.
  • SIGKILL: uncatchable; recovery via invariants 2/3. Unchanged.
  • Metric/alert that would show a problem: shutdown logs ("waiting for pipelines to stop…", "all pipelines stopped gracefully" / "…did not stop in time") now appear for SIGTERM shutdowns that previously produced none.
  • Rollback: revert the one-line registration; no state/format/API change.

Explicit scope boundary

The force-stop escalation (runtime.go:499-519) stopping forcefully in the final exitTimeout/6 interval regardless of checkpoint completion, and ForceStop's ack-safety vs invariant 1, are a pre-existing property of the SIGINT path — not worsened by registering SIGTERM (which now simply reaches the same code). Tightening that needs its own analysis + a chaos harness; tracked in #2519 and scoped to v0.16 lifecycle work. This keeps v0.15.1 to the obviously-correct signal registration.

Tests

  • TestEntrypoint_CancelOnInterrupt_SIGTERM — SIGTERM cancels the context instead of killing the process; verified to fail (signal: terminated) without the fix. Unix-guarded (//go:build unix).
  • pkg/conduit suite passes with -race; lint clean; entrypoint.go compiles for windows/amd64 (only the test is Unix-gated).

🤖 Generated with Claude Code

Conduit registered only os.Interrupt (SIGINT), so SIGTERM — what docker stop,
kubectl delete pod, and systemctl stop send — hit Go's default disposition and
killed the process immediately, running no shutdown code. In-flight records were
not drained and pipelines were not checkpointed, violating data-integrity
invariant 7.

Register syscall.SIGTERM alongside os.Interrupt in CancelOnInterrupt so SIGTERM
drives the same existing graceful-shutdown path SIGINT already drives (first
signal cancels the root context and drains up to exitTimeout; a second signal
still hard-exits). SIGTERM now behaves exactly as SIGINT does today.

Not silent data loss (at-least-once + crash-safe positions recover an abrupt
kill), but a documented-invariant violation that caused duplicate storms and
unclean checkpoints on every container/pod recycle. Pre-existing; ships as the
v0.15.1 patch.

Regression test: CancelOnInterrupt cancels its context on SIGTERM instead of the
process being terminated — verified to fail (signal: terminated) without the fix.

Design doc: docs/design-documents/20260704-graceful-shutdown-sigterm.md. The
force-stop ack-safety follow-up (runtime.go force-stop escalation vs invariant 1)
is tracked separately in #2519 and scoped to the v0.16 lifecycle work.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@devarismeroxa devarismeroxa requested a review from a team as a code owner July 4, 2026 22:05
@devarismeroxa devarismeroxa added this to the v0.15.1 milestone Jul 4, 2026
@devarismeroxa devarismeroxa merged commit d16cd3c into main Jul 4, 2026
8 of 9 checks passed
@devarismeroxa devarismeroxa deleted the fix/2519-sigterm-graceful-shutdown branch July 4, 2026 22:19
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.

SIGTERM does not drain in-flight records (invariant 7 violation)

1 participant