fix(runtime): handle SIGTERM for graceful shutdown (#2519)#2520
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2519. Tier 1 (data path) — requires human sign-off + failure-mode analysis.
Problem
CancelOnInterrupt(entrypoint.go) registered onlyos.Interrupt(SIGINT). SIGTERM — sent bydocker stop,kubectl delete pod, andsystemctl 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.SIGTERMalongsideos.Interruptso SIGTERM drives the same graceful path SIGINT already drives (first signal → cancel root ctx →StopAlldrains up toexitTimeout; 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)
signal.Notifycall, same goroutine). Risk surface is minimal.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.Explicit scope boundary
The force-stop escalation (
runtime.go:499-519) stopping forcefully in the finalexitTimeout/6interval regardless of checkpoint completion, andForceStop'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/conduitsuite passes with-race; lint clean;entrypoint.gocompiles for windows/amd64 (only the test is Unix-gated).🤖 Generated with Claude Code