fix(core): respect Retry-After header on 429 without retiring session#3737
Closed
harryautomazione wants to merge 1 commit into
Closed
fix(core): respect Retry-After header on 429 without retiring session#3737harryautomazione wants to merge 1 commit into
harryautomazione wants to merge 1 commit into
Conversation
barjin
reviewed
Jun 16, 2026
barjin
left a comment
Member
There was a problem hiding this comment.
Hello, and thank you for your interest in this project, @harryautomazione !
The BasicCrawler.delayRequest method is actually deprecated, and we're planning to redesign it in v4. The delays should be a concern of the RequestManager, same as in apify/crawlee-python#1762 .
If you want to give it a try and model the JS solution after the Python implementation, you are very much welcome to do so. Please note the PR with these changes should target the v4 branch.
Cheers!
Author
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.
Motivation:
Currently, when a crawler encounters an HTTP
429 Too Many Requestsstatus code, theSessionPoolinterprets it as an IP block and permanently retires the session. This leads to premature session churn and IP exhaustion, completely ignoring the HTTP standardRetry-Afterheader.Changes:
429fromBLOCKED_STATUS_CODESinsession_pool/consts.tsso the session isn't automatically retired.RateLimitErrorinerrors.tsto capture theretryAfterMsduration.http-crawler, parsing theRetry-Afterheader (both seconds and date strings) to throw the newRateLimitError.basic-crawler: CaughtRateLimitErrorinside_requestFunctionErrorHandlerto automatically updatedomainAccessedTime. This elegantly delays the next request to that domain by the specified cooldown without burning the session.Testing:
http_crawler.test.ts(should respect 429 RateLimitError and retry). It creates a mock endpoint that returns a 429 withRetry-After: 1on the first hit, and 200 OK on the second. The test verifies that the crawler waits for the cooldown (~1000ms) and successfully retries.vitest run test/core/crawlers/http_crawler.test.ts) are still passing successfully.Closes #3623