Repository navigation
fix: ensure resume.cfg captures complete processing state (fixes #2345) - #2391
Simplereally wants to merge 1 commit into
Conversation
Fixes projectdiscovery#2345 where resuming with -r resume.cfg skipped some targets. The resume file was being written with 'current' item being processed rather than the last item that completed output. This caused targets that were in-flight during CTRL+C to be marked as done but never actually processed. Changes: - Add completedIndex and completedInput fields to track actual output - Update resume state after output is committed (not when processing starts) - Use mutex for thread-safe access during concurrent output - Initialize completed fields from loaded config when resuming Fixes projectdiscovery#2345
WalkthroughThe changes refactor resume state tracking to record completion status after output production rather than at earlier timing points, introducing synchronized access via mutex to prevent incomplete state persistence. This addresses the issue where resume files were saved before processing finished, causing skipped targets on resumption. Changes
Sequence DiagramsequenceDiagram
participant Runner
participant ResumeCfg
participant Output
participant SaveLogic
Runner->>ResumeCfg: Load resume config (with error handling)
ResumeCfg-->>Runner: Return completedIndex, completedInput
loop For each processed item
Runner->>Output: Produce output
Output-->>Runner: Output ready
Runner->>ResumeCfg: Lock mu
Runner->>ResumeCfg: Update completedIndex++
Runner->>ResumeCfg: Store completedInput
Runner->>ResumeCfg: Unlock mu
end
Runner->>SaveLogic: SaveResumeConfig()
SaveLogic->>ResumeCfg: Lock mu
SaveLogic->>ResumeCfg: Read completedIndex & completedInput
SaveLogic->>ResumeCfg: Unlock mu
SaveLogic-->>Runner: Resume config persisted
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@runner/runner.go`:
- Around line 1347-1353: The resume logic currently increments
r.options.resumeCfg.completedIndex per output (see
r.options.resumeCfg.completedIndex, r.options.resumeCfg.completedInput and
resp.Input), which diverges from the input-based currentIndex used for skipping;
change the implementation to advance the saved resume index per input instead of
per output — e.g., track completion by input (use a field like
lastFlushedInputIndex or store resp.Input.Index) and only increment or set
completedIndex when the final output for that input has been flushed (or replace
completedIndex semantics with completedInputIndex = resp.Input.Index); ensure
any concurrency uses r.options.resumeCfg.mu as already present when updating the
new per-input marker.
| // Update resume state after output to avoid skipping unprocessed targets on interrupt | ||
| if r.options.resumeCfg != nil { | ||
| r.options.resumeCfg.mu.Lock() | ||
| r.options.resumeCfg.completedIndex++ | ||
| r.options.resumeCfg.completedInput = resp.Input | ||
| r.options.resumeCfg.mu.Unlock() | ||
| } |
There was a problem hiding this comment.
Resume index now counts outputs, which can skip inputs.
At Line 1347–1353, completedIndex increments per output, but resume skipping still compares Index against currentIndex which increments per input. If a single input yields multiple results (multiple methods/ports/paths), completedIndex advances faster than the input index and a resume run can skip unprocessed inputs. Consider tracking completion per input instead of per output (e.g., count expected outputs per input and advance completedIndex only once the last output is flushed), or otherwise align the saved index with the input index semantics.
🤖 Prompt for AI Agents
In `@runner/runner.go` around lines 1347 - 1353, The resume logic currently
increments r.options.resumeCfg.completedIndex per output (see
r.options.resumeCfg.completedIndex, r.options.resumeCfg.completedInput and
resp.Input), which diverges from the input-based currentIndex used for skipping;
change the implementation to advance the saved resume index per input instead of
per output — e.g., track completion by input (use a field like
lastFlushedInputIndex or store resp.Input.Index) and only increment or set
completedIndex when the final output for that input has been flushed (or replace
completedIndex semantics with completedInputIndex = resp.Input.Index); ensure
any concurrency uses r.options.resumeCfg.mu as already present when updating the
new per-input marker.
|
Hi team! This PR has been reviewed and all CI checks pass. Is there anything else needed for merge? Happy to address any feedback. Thanks! |
|
@coderabbitai Good catch. Fixed in 4c0a555 - now we only advance |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 2471
I appreciate you taking the time to implement this fix! 🎉 |
|
Closing for now. Let me know if you'd like me to reopen. |
Summary
Fixes #2345 - resume skips targets due to incomplete state capture.
Problem
Resume file was written using
currentandcurrentIndexwhich track items that started processing, not items that completed. When interrupted, in-flight items were marked as done but never output.Solution
Track completion separately from processing start, update resume state after output is committed.
Changes
completedIndexandcompletedInputfields toResumeCfgSaveResumeConfignow writes the completed stateTesting
Indexfield)/claim #2345
Summary by CodeRabbit
New Features
Bug Fixes