Skip to content

fix: cancel CLI commands on SIGINT/SIGTERM via root context - #97

Merged
lucasew merged 1 commit into
mainfrom
janitor/cli-signal-context
Jul 25, 2026
Merged

fix: cancel CLI commands on SIGINT/SIGTERM via root context#97
lucasew merged 1 commit into
mainfrom
janitor/cli-signal-context

Conversation

@lewtec-bot

@lewtec-bot lewtec-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Problem

get, seed, and server already use cmd.Context() for in-flight HTTP and shutdown, but Execute called plain rootCmd.Execute() with a non-cancelable background context.

SIGINT/SIGTERM therefore only stopped the process via the default fatal signal path. In-flight downloads were not canceled through context, and command defers (temp cleanup, etc.) did not get a normal return path.

Change

  • Install signal.NotifyContext for SIGINT/SIGTERM at the process root
  • Run the CLI with ExecuteContext so cancel reaches every subcommand
  • Tests: command context is derived from execute's context (including already-canceled)

server still installs its own nested NotifyContext for graceful Shutdown; that remains valid when the parent context is also signal-aware.

Verify

go test ./cmd/fetchurl/ -count=1 -p 1

get, seed, and server already honor cmd.Context() for in-flight HTTP
and shutdown, but Execute used plain Execute() with a non-cancelable
background context. Install signal.NotifyContext at the process root
so Ctrl-C/SIGTERM aborts downloads and lets defers run instead of
relying on an uncatchable process kill.
@lewtec-bot
lewtec-bot Bot requested a review from lucasew July 25, 2026 03:49
@lucasew
lucasew merged commit 66047ef into main Jul 25, 2026
1 check 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.

1 participant