fix(throttling-manager): Correct the backoff for concurrent 429s and zero Retry-After - #2159
Open
Mantisus wants to merge 1 commit into
Open
fix(throttling-manager): Correct the backoff for concurrent 429s and zero Retry-After#2159Mantisus wants to merge 1 commit into
Mantisus wants to merge 1 commit into
Conversation
Collaborator
|
@janbuchar Does #2158 (comment) apply to this PR as well, or can this one be reviewed and merged? |
Collaborator
|
@vdusek I believe this one is free to go. I'll look into it. |
Contributor
There was a problem hiding this comment.
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-Afterfrom 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 cappedRetry-Afterdeadline (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_delaycap is applied. With the default delays, a continuously rate-limited domain reaches this after roughly 47 backoff events, at which pointtimedelta * intraisesOverflowErrorand 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
max_delayin one go, and any handled request reset the counter, including one that had just failed for good.throttled_untilsplit into separatebackoff_untilandcrawl_delay_untilclocks, since the crawl delay is armed on every dispatch and would otherwise pass for an active backoff.Issues
ThrottlingRequestManagercomputes the wrong backoff for concurrent 429s and forRetry-After: 0#2125Testing