Repository navigation
fix(cbz-fix): stop cleanly on Ctrl+C and pass a context to magick - #304
Merged
Merged
Conversation
… print the partial summary
…pt kills no child and hides no failure
…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
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.
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, whichnoctxneeds before it can be enabled. This PR is cbz-fix only and sets the shape the other five modules will copy (interrupt.go,command*.goand their tests).Change
cbz-fix/interrupt.go:interruptContextreturns 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| teereader 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).commandErrreports 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; onlycontext.Canceledcounts as the interrupt, other errors are still printed and counted; the summary is printed headedInterrupted, exit 130. The--update-coverprompt 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 | headstill 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
nohupand 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).cbz-fix lib 2>&1 | tee logplus 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.