Skip to content

Crawlee—A web scraping and browser automation library for Node.js to build reliable crawlers. In JavaScript and TypeScript. Extract data for AI, LLMs, RAG, or GPTs. Download HTML, PDF, JPG, PNG, and other files from websites. Works with Puppeteer, Playwright, Cheerio, JSDOM, and raw HTTP. Both headful and headless mode. With proxy rotation.

fix: clean up `inProgress` cache when delaying requests via `sameDomainDelaySecs` (#2045)

Martin Adámekf63ccc018c9e
diff --git a/packages/basic-crawler/src/internals/basic-crawler.ts b/packages/basic-crawler/src/internals/basic-crawler.ts
index 80a87b20d..90ff27c73 100644
--- a/packages/basic-crawler/src/internals/basic-crawler.ts
+++ b/packages/basic-crawler/src/internals/basic-crawler.ts
@@ -982,7 +982,7 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
* adding it back to the queue after the timeout passes. Returns `true` if the request
* should be ignored and will be reclaimed to the queue once ready.
*/
- protected delayRequest(request:Request, source: RequestQueue | RequestList) {
+ protected delayRequest(request: Request, source: RequestQueue | RequestList) {
const domain = getDomain(request.url);
if (!domain || !request) {
@@ -997,10 +997,12 @@ export class BasicCrawler<Context extends CrawlingContext = BasicCrawlingContext
return false;
}
+ source.inProgress.delete(request.id!);
const delay = lastAccessTime + this.sameDomainDelayMillis - now;
this.log.debug(`Request ${request.url} (${request.id}) will be reclaimed after ${delay} milliseconds due to same domain delay`);
setTimeout(async () => {
this.log.debug(`Adding request ${request.url} (${request.id}) back to the queue`);
+ source?.inProgress.add(request.id!);
await source?.reclaimRequest(request);
}, delay);