Skip to content

lint: enable noctx and thread a context through HTTP and subprocess calls #294

Backlog

Description

@robrich82

Deferred from the lint adoption stack (#286–#290). golangci-lint run --enable-only noctx reports 68 findings across all six modules: exec.Command, http.NewRequest and (*http.Client).Get with no context. 45 are in non-test code, the rest in tests (t.Context() covers those).

Module Findings
cbz-fix 2
mkv-audit 8
mkv-movie 16
mkv-music 12
mkv-tvshow 17
sw-update 9

No tool uses context today. A root context from signal.NotifyContext in each main makes Ctrl+C cancel in-flight HTTP and subprocesses instead of killing the process outright, so cleanup and cache writes get a chance to run. Enable noctx in .golangci.yml once every module is clean.

Activity

  1. robrich82 commented on Nov 29, 2026

    @robrich82
    OwnerAuthor

    Pattern settled in the cbz-fix PR (#304), for the other modules to copy (interrupt.go, command.go, command_unix.go, command_windows.go, command_other.go and their tests):

    • interruptContext(): the first Ctrl+C cancels ctx (stop between steps). The second also cancels a separate kill context that ctx carries, then restores Ctrl+C's default handling, so a third quits at once. A quit signal (quitSignals: SIGTERM, plus SIGHUP on Unix; Go reports a closed console as SIGTERM on Windows) does stop and kill at once. Quit signals stay caught afterwards: a closed terminal sends SIGHUP twice, and a default-handled second one would end the tool before its children were killed. Signals the process started out ignoring (SIGHUP under nohup) stay ignored. From the first stop, SIGPIPE (pipeSignals) is caught, so a | tee reader ended by the same Ctrl+C can't kill the tool by SIGPIPE before it finishes stopping; before any stop, tool | head still dies by SIGPIPE as usual.
    • Children: build each with command(ctx, name, args...). Only the kill context kills it; ctx's own cancel and deadline never do. It is isolated from the terminal's Ctrl+C (Unix: own process group, cancelled with SIGTERM to the group; Windows: CREATE_NO_WINDOW). commandErr(ctx, err) reports a failure after the kill as the interrupt.
      • In-place editors (mkvpropedit) must never be killed mid-write: run them without the kill context.
      • Interactive children that own the terminal (sw-update installers): no isolation, context.WithoutCancel.
    • ctx is checked between steps (pages, files, walk entries), returning ctx.Err(). HTTP requests take ctx directly.
    • Only errors.Is(err, context.Canceled) counts as the interrupt; every other error is still printed and counted. After the walk, ctx.Err() is returned, so an interrupt during the last file still reports one.
    • Prompts read in a goroutine and select on ctx; an EOF waits up to 250ms for the cancel (on Windows a Ctrl+C at a prompt can arrive as EOF first).
    • An interrupt prints the summary so far, headed Interrupted, and exits 130.
    • Tests: Unix helper children that signal themselves (TestInterruptContext, TestInterruptContext_BrokenPipe), TestWatchSignals with fake channels, TestCommandErr.

    Deferred: on Unix, exiting 130 instead of re-raising SIGINT means a bash loop over a tool carries on to the next item after Ctrl+C. Fixing it needs signal.Reset plus re-raising the signal in a Unix-only file in every module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions