Skip to content

Cancel the root context on interrupt and termination signals - #178

Merged
nickschuch merged 1 commit into
mainfrom
fix/signal-handling-graceful-shutdown
Sep 4, 2026
Merged

Cancel the root context on interrupt and termination signals#178
nickschuch merged 1 commit into
mainfrom
fix/signal-handling-graceful-shutdown

Conversation

@nickschuch

Copy link
Copy Markdown
Contributor

Both binaries called cobra's cmd.Execute(), which gives cmd.Context() a plain context.Background() that is never cancelled. In the sidecar this left the graceful-shutdown block (server.Shutdown with a 5s timeout) and the tracer cleanup defers unreachable on a normal docker stop: Go terminates on SIGTERM without running them.

Wire signal.NotifyContext(os.Interrupt, SIGTERM) into a root context and pass it via cmd.ExecuteContext, so cmd.Context() cancels on a stop signal and the existing errgroup-driven shutdown runs. The CLI is largely covered by bubbletea already, but is switched too for consistency and deterministic teardown of the collector goroutine.

Both binaries called cobra's cmd.Execute(), which gives cmd.Context() a plain
context.Background() that is never cancelled. In the sidecar this left the
graceful-shutdown block (server.Shutdown with a 5s timeout) and the tracer
cleanup defers unreachable on a normal docker stop: Go terminates on SIGTERM
without running them.

Wire signal.NotifyContext(os.Interrupt, SIGTERM) into a root context and pass
it via cmd.ExecuteContext, so cmd.Context() cancels on a stop signal and the
existing errgroup-driven shutdown runs. The CLI is largely covered by
bubbletea already, but is switched too for consistency and deterministic
teardown of the collector goroutine.
@nickschuch
nickschuch merged commit 9bd9d94 into main Sep 4, 2026
5 checks passed
@nickschuch
nickschuch deleted the fix/signal-handling-graceful-shutdown branch September 4, 2026 01:56
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