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.
TypeScript apifyautomationcrawlercrawlingheadlessheadless-chromejavascriptnodejsnpmplaywrightpuppeteerscraperscrapingtypescriptweb-crawlerweb-crawlingweb-scraping
chore: adjust internal timeouts (#1251)
Martin Adámekffce817177d2
diff --git a/src/crawlers/basic_crawler.js b/src/crawlers/basic_crawler.jsindex 2c8468dc1..6bb6d8ab6 100644--- a/src/crawlers/basic_crawler.js+++ b/src/crawlers/basic_crawler.js@@ -261,6 +261,7 @@ export class BasicCrawler {this.userProvidedHandler = handleRequestFunction;this.failedContextHandler = handleFailedRequestFunction;this.handleRequestTimeoutMillis = handleRequestTimeoutSecs * 1000;+ this.internalTimeoutMillis = Math.max(this.handleRequestTimeoutMillis, 300e3); // allow at least 5min for internal timeoutsthis.handleFailedRequestFunction = handleFailedRequestFunction;this.maxRequestRetries = maxRequestRetries;this.handledRequestsCount = 0;@@ -486,8 +487,8 @@ export class BasicCrawler {request = await this._fetchNextRequest();}},- this.handleRequestTimeoutMillis,- `Fetching next request timed out after ${this.handleRequestTimeoutMillis / 1e3} seconds.`,+ this.internalTimeoutMillis,+ `Fetching next request timed out after ${this.internalTimeoutMillis / 1e3} seconds.`,);tryCancel();@@ -515,14 +516,13 @@ export class BasicCrawler {this.handleRequestTimeoutMillis,`handleRequestFunction timed out after ${this.handleRequestTimeoutMillis / 1000} seconds.`,);- tryCancel();await this._timeoutAndRetry(() => source.markRequestHandled(request),- this.handleRequestTimeoutMillis,- `Marking request ${request.url} as handled timed out after ${this.handleRequestTimeoutMillis / 1e3} seconds.`,+ this.internalTimeoutMillis,+ `Marking request ${request.url} as handled timed out after ${this.internalTimeoutMillis / 1e3} seconds.`,);- tryCancel();+this.stats.finishJob(statisticsId);this.handledRequestsCount++;@@ -532,8 +532,8 @@ export class BasicCrawler {try {await this._timeoutAndRetry(() => this._requestFunctionErrorHandler(err, crawlingContext, source),- this.handleRequestTimeoutMillis,- `Handling request failure of ${request.url} timed out after ${this.handleRequestTimeoutMillis / 1e3} seconds.`,+ this.internalTimeoutMillis,+ `Handling request failure of ${request.url} timed out after ${this.internalTimeoutMillis / 1e3} seconds.`,);} catch (secondaryError) {this.log.exception(secondaryError, 'runTaskFunction error handler threw an exception. '@@ -546,8 +546,6 @@ export class BasicCrawler {} finally {this.crawlingContexts.delete(crawlingContext.id);}-- tryCancel();}/**diff --git a/src/storages/request_queue.js b/src/storages/request_queue.jsindex db9c38d35..666e85187 100644--- a/src/storages/request_queue.js+++ b/src/storages/request_queue.js@@ -13,6 +13,7 @@ import Request, { RequestOptions } from '../request'; // eslint-disable-line impimport { ApifyClient } from 'apify-client';// @ts-ignoreimport { ApifyStorageLocal } from '@apify/storage-local';+import { tryCancel } from '@apify/timeout';/* eslint-enable no-unused-vars,import/named,import/no-duplicates,import/order */const MAX_CACHED_REQUESTS = 1000 * 1000;@@ -407,6 +408,8 @@ export class RequestQueue {// Wait a little to increase a chance that the next call to fetchNextRequest() will return the request with updated data.// This is to compensate for the limitation of DynamoDB, where writes might not be immediately visible to subsequent reads.setTimeout(() => {+ tryCancel();+if (!this.inProgress.has(request.id)) {this.log.warning('The request is no longer marked as in progress in the queue?!', { requestId: request.id });return;