Skip to content

fix(scan): bound crawl breadth with a page budget - #269

Merged
vmfunc merged 1 commit into
vmfunc:mainfrom
TBX3D:fix/crawl-breadth-budget
Jul 22, 2026
Merged

vmfunc merged 1 commit into
vmfunc:mainfrom
TBX3D:fix/crawl-breadth-budget

Conversation

@TBX3D

@TBX3D TBX3D commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

MaxDepth bounds recursion depth but nothing bounds breadth, so fetch count grows as branching^depth. Repro before the fix: a depth-3 crawl of one page linking 40 fresh urls issued 1641 real fetches; after, it stops at the 500-page budget and sets Truncated.

Verified by crawl_budget_test.go: a server linking past the budget caps visited at maxCrawlPages and flags Truncated; an under-budget crawl leaves it false. Race-clean, the counter is atomic since colly fires callbacks across goroutines.

Scope: only the runaway-breadth ceiling. A crawl-wide context deadline is a separate root cause and its own PR.

Crawl only capped recursion depth, not breadth per level. A link-heavy page
(pagination, faceted search) drives fetch count toward branching^depth with no
ceiling: a depth-3 crawl of a page linking 40 fresh urls issued 1641 real
fetches.

Cap total fetches at a page budget via an atomic counter in an OnRequest hook
that aborts once exceeded, and add a Truncated flag on CrawlResult so callers
can tell a run was cut short.
@TBX3D
TBX3D requested a review from vmfunc as a code owner July 3, 2026 08:32
@github-actions github-actions Bot added scan changes to scan engine tests test changes size/m <200 lines changed labels Jul 3, 2026
@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

pr summary

2 files changed (+101 -2)

category files
go source 2
tests 1

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@3a289a3). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #269   +/-   ##
=======================================
  Coverage        ?   54.78%           
=======================================
  Files           ?       81           
  Lines           ?     6882           
  Branches        ?        0           
=======================================
  Hits            ?     3770           
  Misses          ?     2842           
  Partials        ?      270           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vmfunc vmfunc left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

counting in OnRequest before the dial is the right spot, abort lands before any fetch. counter is 1..500 pass and 501 aborts, so exactly maxCrawlPages get fetched, clean. Truncated read after Wait() so no race with the callbacks. scoping the context deadline out to its own PR is the right call. in.

@vmfunc
vmfunc merged commit 0d96838 into vmfunc:main Jul 22, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scan changes to scan engine size/m <200 lines changed tests test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants