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
fix: limit `handleRequestTimeoutMillis` to max valid value (#1116)
Szymon Marczak594895835222
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 388a72855..4c930c561 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,6 +1,7 @@2.0.3 / BETA====================- **BREAKING IN EDGE CASES** - We removed `forceUrlEncoding` in `requestAsBrowser` because we found out that recent versions of the underlying HTTP client `got` already encode URLs and `forceUrlEncoding` could lead to weird behavior. We think of this as fixing a bug, so we're not bumping the major version.+- Limit `handleRequestTimeoutMillis` to max valid value to prevent Node.js fallback to `1`.2.0.2 / 2021/08/12====================diff --git a/src/crawlers/basic_crawler.js b/src/crawlers/basic_crawler.jsindex 0a6205761..c29750fdc 100644--- a/src/crawlers/basic_crawler.js+++ b/src/crawlers/basic_crawler.js@@ -269,6 +269,14 @@ export class BasicCrawler {this.useSessionPool = useSessionPool;this.crawlingContexts = new Map();+ const maxSignedInteger = 2 ** 31 - 1;+ if (this.handleRequestTimeoutMillis > maxSignedInteger) {+ log.warning(`handleRequestTimeoutMillis ${this.handleRequestTimeoutMillis}`+ + `does not fit a signed 32-bit integer. Limiting the value to ${maxSignedInteger}`);++ this.handleRequestTimeoutMillis = maxSignedInteger;+ }+let shouldLogMaxPagesExceeded = true;const isMaxPagesExceeded = () => maxRequestsPerCrawl && maxRequestsPerCrawl <= this.handledRequestsCount;diff --git a/test/crawlers/basic_crawler.test.js b/test/crawlers/basic_crawler.test.jsindex acc8a36f3..ff7ec3b44 100644--- a/test/crawlers/basic_crawler.test.js+++ b/test/crawlers/basic_crawler.test.js@@ -603,6 +603,24 @@ describe('BasicCrawler', () => {results[0].errorMessages.forEach((msg) => expect(msg).toMatch('handleRequestFunction timed out'));});+ test('limits handleRequestTimeoutSecs to a valid value', async () => {+ const url = 'https://example.com';+ const requestList = new Apify.RequestList({ sources: [{ url }] });+ await requestList.initialize();++ const results = [];+ const crawler = new Apify.BasicCrawler({+ requestList,+ handleRequestTimeoutSecs: Infinity,+ maxRequestRetries: 1,+ handleRequestFunction: () => utils.sleep(1000),+ handleFailedRequestFunction: ({ request }) => results.push(request),+ });++ const maxSignedInteger = 2 ** 31 - 1;+ expect(crawler.handleRequestTimeoutMillis).toBe(maxSignedInteger);+ });+describe('Uses SessionPool', () => {it('should use SessionPool when useSessionPool is true ', async () => {const url = 'https://example.com';