Skip to content

fix: prevent resume from skipping in-flight items - #2390

Closed
Simplereally wants to merge 1 commit into
projectdiscovery:devfrom
Simplereally:fix/resume-inflight-items
Closed

Simplereally wants to merge 1 commit into
projectdiscovery:devfrom
Simplereally:fix/resume-inflight-items

Conversation

@Simplereally

@Simplereally Simplereally commented Feb 2, 2026 •

Copy link
Copy Markdown

Summary

This PR fixes the resume functionality to prevent skipping items that were in-flight when Ctrl+C was pressed.

Problem

When httpx is interrupted with Ctrl+C, the resume file saves currentIndex which includes items that were queued for processing but hadn't completed yet. On resume, these in-flight items would be skipped because their index was already counted, causing missing output.

Root cause: The currentIndex is incremented at the start of processItem, before r.process() spawns goroutines for the actual HTTP requests. When saving resume during interrupt, up to Threads items could be in-flight.

Solution

When saving the resume config, subtract the thread count from currentIndex to get a "safe" index:

safeIndex := r.options.resumeCfg.currentIndex - r.options.Threads
if safeIndex < 0 {
    safeIndex = 0
}
resumeCfg.Index = safeIndex

This is a conservative fix: it may re-process a few items that had already completed, but this is safe (httpx handles duplicates) while skipping items is not.

Testing

  • Added unit tests for the fix in runner/resume_test.go
  • Manual testing: Verified resume now includes previously skipped items

Checklist

  • Code compiles correctly
  • Tests pass
  • Documentation is up to date

/claim #2345

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced resume point calculation to safely handle concurrent requests in flight. The system now accounts for items still being processed, preventing potential data loss by adjusting where operations resume to avoid skipping unfinished requests.
  • Tests

    • Added unit tests for resume configuration, including edge cases for concurrent thread handling and index boundary conditions.

When Ctrl+C is pressed, the resume file now saves an index that is
(currentIndex - Threads) to account for items that may be in-flight
but not yet completed. This ensures that on resume, these items will
be re-processed rather than skipped.

The issue occurred because currentIndex was incremented at the start
of processItem, before the actual HTTP request completed. When saving
resume config during interrupt, up to Threads items could be in-flight.
On resume, these items would be skipped because their index was already
counted.

The fix is conservative: it may re-process a few items that had already
completed, but this is safe (httpx handles duplicates) while skipping
items is not.

Fixes projectdiscovery#2345
@coderabbitai

coderabbitai Bot commented Feb 2, 2026 •

Copy link
Copy Markdown

Walkthrough

Introduces a safety adjustment to the SaveResumeConfig function by subtracting the concurrent thread count from the current index before persistence, with a minimum floor of zero. This prevents skipping items still processing during resume operations, with new unit tests validating the calculation logic.

Changes

Cohort / File(s) Summary
Resume Safety Logic
runner/runner.go, runner/resume_test.go
Modified SaveResumeConfig to calculate safeIndex by subtracting Threads from currentIndex (floored at 0) before persistence. Added two unit tests validating subtraction behavior and zero-floor clamping.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A thread-safe hop through resume's lane,
Subtracting concurrent paths to avoid the pain,
Safety adjusted, never below zero we go,
In-flight items preserved, a thoughtful flow! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: prevent resume from skipping in-flight items' directly and clearly describes the main change in the pull request—a fix to prevent in-flight items from being skipped during resume operations.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Simplereally

Copy link
Copy Markdown
Author

Hi @Mzack9999 @ehsandeep 👋 This PR fixes the resume.cfg skip issue (#2345) with a thread-safe approach. Ready for review whenever you have a moment. Thanks! 🙏

@Simplereally

Copy link
Copy Markdown
Author

Closing in favor of #2391 which has proper mutex protection and more precise tracking. Will refine #2391 instead.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant