Skip to content

fix(cbz-fix): stop cleanly on Ctrl+C and pass a context to magick - #304

Merged
robrich82 merged 10 commits into
mainfrom
fix/noctx-cbz-fix
Dec 4, 2026
Merged

robrich82 merged 10 commits into
mainfrom
fix/noctx-cbz-fix

Conversation

@robrich82

Copy link
Copy Markdown
Owner

Part of #294

Problem

Ctrl+C in cbz-fix killed it at once, so magick could be killed mid-page and a comic left half-written; and cbz-fix had no context.Context, which noctx needs before it can be enabled. This PR is cbz-fix only and sets the shape the other five modules will copy (interrupt.go, command*.go and their tests).

Change

  • cbz-fix/interrupt.go: interruptContext returns a ctx that the first Ctrl+C cancels (run stops before the next page conversion or file). The second also cancels a separate kill context; the third gets the default handling. A quit signal (SIGTERM; on Unix also SIGHUP) does stop and kill at once. Quit signals stay caught afterwards, since a closed terminal sends SIGHUP twice and a default-handled second one ended cbz-fix before magick was signalled. Signals the process started out ignoring (SIGHUP under nohup) stay ignored. From the first stop, SIGPIPE is caught too, so a | tee reader that the same Ctrl+C ended can't kill cbz-fix by SIGPIPE before it finishes stopping.
  • cbz-fix/command*.go: command(ctx, ...) runs children that only the kill context kills, isolated from the terminal's Ctrl+C (own process group on Unix, killed with SIGTERM to the group so ImageMagick removes its temp files; own hidden console on Windows). commandErr reports a failure after the kill as the interrupt.
  • cbz-fix/main.go, processor.go, convert.go: ctx is checked between pages, files and walk entries; only context.Canceled counts as the interrupt, other errors are still printed and counted; the summary is printed headed Interrupted, exit 130. The --update-cover prompt returns on Ctrl+C.
  • README.md: the Ctrl+C behaviour.

Behavior

Before: Ctrl+C killed cbz-fix and magick wherever they were. After: one Ctrl+C finishes the page in progress, leaves a part-done comic unchanged, prints the summary and exits 130; a second kills magick; a third quits at once. cbz-fix | head still dies by SIGPIPE as before when nothing was interrupted.

Left for #294: re-raising SIGINT instead of exiting 130 (a shell loop carries on after Ctrl+C); the five other modules; enabling noctx.

Verification

mise run vet        # 0 issues
mise run vet-linux  # 0 issues
mise run test       # ok cbz-fix
mise run build      # ok
  • Linux: the test binary passes in WSL Ubuntu, also under nohup and with the signal tests at -count=20. The Unix signal tests run children that signal themselves (three Ctrl+Cs, hangup and SIGTERM twice, broken pipe before and after Ctrl+C, ignored SIGHUP/SIGINT).
  • Mutation script: one-line mutants of the signal wiring, kill path and error reporting are all caught, except the order of the SIGPIPE catch versus the cancel (a scheduling race).
  • Real terminal (WSL pty, fake magick): cbz-fix lib 2>&1 | tee log plus one Ctrl+C exited 141 with no summary in 4/4 runs before the SIGPIPE catch, and 130 in 12/12 after (stdout, stderr or both piped). Closing the terminal mid-conversion: magick gets SIGTERM, no orphan, no temp file left.

AI assistance

Written with Claude Code (Claude Opus 5.5), which self-reviewed the diff over several rounds and ran the checks above.

…k from magick, make the prompt interruptible
…lk error after Ctrl+C, and shape command for the ports
…ter a quit, and split out the signal code for the ports
…n magick, drop the EOF latch, and pin the signal wiring with real signals
…he same Ctrl+C can't end cbz-fix, and pin SIGTERM and the absorbed second quit
…-pipe helper failures, and correct the signal docs
…, fail rather than panic on a child that never started, and tighten the signal docs
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