Repository navigation
Exit 130 When a Ctrl+C Ends a Tool Before the Signal Handler Runs - #1310
Conversation
A terminal Ctrl+C signals the whole process group, so a running tool can exit before PlexCleaner's asynchronously dispatched signal handler runs. A failed command now waits for that handler before choosing its exit code, startup tool verification reports the cancel rather than a missing tool, and an interrupted file is kept as cancelled rather than as a tool error. The handlers register before the logger is created, and a cancelled tool run logs a warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A tool that the same signal ended before the handler ran returns an ordinary failed result, so LogFailedResult and the FFmpeg verify log it as a failed execution at error level. Both now log it as cancelled at warning level once the cancel is seen, and folder tool verification skips its "not found" error on a cancel as system tool verification does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The FFmpeg verify logged its failed execution inline with a copy of LogFailedResult's templates, so the cancel check had two homes. Both now call LogFailedExecution, and the FFprobe analysis packet scan logs a cancel as a warning too. Moving the signal registration ahead of the logger fixed none of the startup failures, since tool verification runs inside the command, so it returns to where it was. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
A recorded local strict-review pass covers head |
PR Summary by QodoPreserve signal exit codes and cancellation status when tools exit first
AI Description
Merge Risk
|
Code Review by Qodo
1. Failed media files slow batch processing
|
There was a problem hiding this comment.
🟡 Changes recommended
Approval is blocked by three active nit findings: an unclear cancellation history entry and duplicated cancellation-handling logic that should be centralized.
1 open issue
What changed in this PR
This PR hardens Ctrl+C handling when a child media tool exits before PlexCleaner’s signal handler runs. It preserves signal-derived exit codes, classifies interrupted files as cancelled, suppresses misleading startup errors, and adjusts cancellation logging.
Changes:
- Waits briefly for pending signal handling before selecting the final exit code.
- Treats interrupted tool verification and media processing as cancellation.
- Centralizes failed-tool logging behavior and records cancelled executions at warning level.
- Documents the updated cancellation behavior.
| File | Description |
|---|---|
| PlexCleaner/Tools.cs | Detects cancellation during system and folder tool verification to avoid misleading missing-tool errors. |
| PlexCleaner/Program.cs | Waits for pending signal handling before finalizing failed command exit codes. |
| PlexCleaner/ProcessFile.cs | Prioritizes cancelled processing when determining the reason an interrupted file is retained. |
| PlexCleaner/MediaTool.cs | Centralizes failed-execution logging and records cancelled tool runs as warnings. |
| PlexCleaner/FfProbeTool.cs | Handles cancelled packet analysis and applies warning-level cancellation logging. |
| PlexCleaner/FfMpegTool.cs | Routes verification failures through the shared cancellation-aware logger. |
| HISTORY.md | Documents the updated Ctrl+C exit-code, file-state, and cancellation-logging behavior. |
Review effort: Lite
The three cancelled-token catches each logged the same cancelled execution warning and recorded a tool error. RecordCancelledExecution now does both beside LogFailedExecution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A recorded local strict-review pass covers head |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@qodo-free-for-open-source-projects please dismiss the finding "Failed media files slow batch processing" at Disproven. The up-to-100 ms wait is the fix itself, not an accidental cost.
|
I haven't dismissed it. The published report lists "Failed media files slow batch processing" as Options:
Your reasoning is clear: the 100 ms wait only runs on failed tool runs and guards against the SIGINT race. If the finding is dismissed, the report should still reflect that decision. |
|
A recorded local strict-review pass covers head |
|
@coderabbitai review |
Action performed
|

Why
A terminal Ctrl+C signals the whole foreground process group, so a running tool receives SIGINT at the same instant as PlexCleaner. .NET dispatches a
PosixSignalRegistrationhandler asynchronously on a separate thread. So the tool can exit and fail the command before the handler has cancelled the run or set the exit code.Measured in the Docker image, a Ctrl+C during startup tool verification logged the tool as not found and exited 1 rather than 130. A file interrupted mid-tool was kept as a tool error rather than as cancelled, with the cancelled tool run logged at error level.
What Changes
IsCancelledError()for a pending handler beforeMainreads the signal exit code.Cancelledahead ofTool errorandTool signal.MediaTool.LogFailedExecution, whichLogFailedResultand the FFmpeg verify now share.Verification
ptr727/plexcleaneragainst a framework-dependent publish ofdevelop, with synthetictestsrc2media and Ctrl+C sent through the container's terminal at identical delays.developexited 1 in 4 runs, each logging a tool as not found. This branch exited 130 in every run that the signal reached.docker stopwith a tool running:developloggedERR Cancelled executionorERR Failed executionand kept the file asTool errororTool signal. This branch loggedWRN Cancelled executionand kept it asCancelled. Both exited 130 or 143 with the summary logged.Program's cancel source is process-wide and deliberately never reset or disposed, so a unit test cannot cancel it without cancelling every later test. The image A/B above is the verification.docker stop,docker kill --signal INT,QUIT, andTERM, Ctrl+\, a proxied signal to a non-TTY client, and--init.Findings from the Local Review
The opening push left these open once the local strict review's edit budget was spent. Each has its outcome:
PlexCleaner/MediaTool.csandPlexCleaner/FfProbeTool.cs,introduced, design: the cancelled-token catches each repeated the cancelled-execution warning and the tool error record. Fixed in 2188b94, which moves them ontoRecordCancelledExecution.PlexCleaner/FfProbeTool.csGetAnalysisPackets,introduced, design: its failure branch checks the cancel by hand rather than callingLogFailedExecution. Declined by the maintainer's decision. Routing it through the helper would thread an exit code throughGetPacketsandGetPacketsAsync. It would also change a real failure's log from the full FFprobe stderr to a one-line summary.Related
#1309 stays open. Its internal CLR error did not reproduce in about 120 interrupted runs, and this change fixes the race it describes rather than that fault. The fleet-wide .NET interrupt rule these findings led to is ptr727/ProjectTemplate#4507.
The
commentslabel is on this pull request because the exit-code comment inProgram.Mainis reworded. It states the race, which the code alone does not carry.🤖 Generated with Claude Code
Summary by CodeRabbit