Skip to content

fix(throttling-manager): Correct the backoff for concurrent 429s and zero Retry-After - #2159

Open
Mantisus wants to merge 1 commit into
apify:masterfrom
Mantisus:fix-backoff-429
Open

fix(throttling-manager): Correct the backoff for concurrent 429s and zero Retry-After#2159
Mantisus wants to merge 1 commit into
apify:masterfrom
Mantisus:fix-backoff-429

Conversation

@Mantisus

Copy link
Copy Markdown
Collaborator

Description

  • Only the first 429 of a burst now advances the exponent, and it decays once the domain has left us alone for a full extra backoff window. Previously every concurrent 429 stepped it, so eight in-flight requests pushed the delay from 2s to past max_delay in one go, and any handled request reset the counter, including one that had just failed for good. throttled_until split into separate backoff_until and crawl_delay_until clocks, since the crawl delay is armed on every dispatch and would otherwise pass for an active backoff.

Issues

Testing

  • Added new unit tests

@Mantisus Mantisus self-assigned this Aug 14, 2026
@vdusek

vdusek commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

@janbuchar Does #2158 (comment) apply to this PR as well, or can this one be reviewed and merged?

@Mantisus
Mantisus requested a review from janbuchar August 19, 2026 10:55
@janbuchar

Copy link
Copy Markdown
Collaborator

@vdusek I believe this one is free to go. I'll look into it.

@vdusek
vdusek requested review from apify-factory and a balanced review from Copilot August 20, 2026 09:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes throttling backoff behavior for concurrent 429 responses and zero-valued Retry-After headers.

Changes:

  • Separates 429 backoff and crawl-delay clocks.
  • Adds burst-aware backoff counting and decay.
  • Expands unit coverage for throttling edge cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/crawlee/request_loaders/_throttling_request_manager.py Revises backoff state and scheduling.
src/crawlee/_utils/http.py Treats non-positive retry delays as unusable.
tests/unit/test_throttling_request_manager.py Tests concurrent 429s, decay, and zero retry delays.
Suppressed comments (2)

src/crawlee/request_loaders/_throttling_request_manager.py:314

  • This early return also discards a positive Retry-After from later responses in the same burst. For example, if the first 429 starts the 2-second default backoff and a concurrent response then specifies 30 seconds, the domain is retried after 2 seconds despite the server's header. Keep the exponent unchanged for the burst, but still extend the active deadline to the later of the current deadline and the capped Retry-After deadline (including the existing cap warning).
        if now < state.backoff_until:
            return True

src/crawlee/request_loaders/_throttling_request_manager.py:327

  • The exponential multiplication can overflow before the subsequent max_delay cap is applied. With the default delays, a continuously rate-limited domain reaches this after roughly 47 backoff events, at which point timedelta * int raises OverflowError and can abort crawling. Saturate overflow before applying the existing cap.
            delay = self._base_delay * (2 ** (state.consecutive_429_count - 1))

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

result = await manager.mark_request_as_handled(request)
self.record_success(request.url)
return result
return await manager.mark_request_as_handled(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ThrottlingRequestManager computes the wrong backoff for concurrent 429s and for Retry-After: 0

5 participants