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!: stop raising the global `EventEmitter.defaultMaxListeners` on import (#4164)

Noah8cb2eb61a035
diff --git a/docs/upgrading/upgrading-v4/upgrading-v4.md b/docs/upgrading/upgrading-v4/upgrading-v4.md
index 8679cf97c..7793c2e15 100644
--- a/docs/upgrading/upgrading-v4/upgrading-v4.md
+++ b/docs/upgrading/upgrading-v4/upgrading-v4.md
@@ -286,6 +286,12 @@ Configuration instances are immutable — attempting to assign a property throws
Previously, environment variables always won. Now `new Configuration({ headless: false })`
works even when `CRAWLEE_HEADLESS=true` is set.
+#### Importing Crawlee no longer raises `EventEmitter.defaultMaxListeners`
+
+Crawlee no longer sets Node's global `EventEmitter.defaultMaxListeners` to 50 on import. Set it yourself if you relied on it.
+
+Each running crawler adds a `SIGINT` listener to `process`, so running more than 10 crawlers at once in the same process now logs a `MaxListenersExceededWarning`. Raise the limit with `process.setMaxListeners()` if you do that.
+
### `KeyValueStore.getInput()` and `Configuration.inputKey` moved to the Apify SDK
Reading the run input is an Apify platform concern, so Crawlee no longer has any notion of it:
diff --git a/packages/core/src/configuration.ts b/packages/core/src/configuration.ts
index b118069d8..911dd0ffe 100644
--- a/packages/core/src/configuration.ts
+++ b/packages/core/src/configuration.ts
@@ -1,4 +1,3 @@
-import { EventEmitter } from 'node:events';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
@@ -7,12 +6,6 @@ import { z } from 'zod';
import { log, LogLevel } from './log.js';
import { serviceLocator } from './service-locator.js';
-// Crawlee attaches many listeners to shared EventEmitters (one per crawler/session/autoscaled pool),
-// which can exceed Node's default limit of 10 and trigger spurious MaxListenersExceededWarning logs.
-// Raising the global default avoids false positives; real leaks will still manifest as unbounded growth.
-// TODO: tracked in https://github.com/apify/crawlee/issues/3615 — find a less side-effecting place for this.
-EventEmitter.defaultMaxListeners = 50;
-
// --- Field definition helpers ---
export interface ConfigField<T extends z.ZodType = z.ZodType> {
diff --git a/test/core/configuration.test.ts b/test/core/configuration.test.ts
index 330be8948..078258de8 100644
--- a/test/core/configuration.test.ts
+++ b/test/core/configuration.test.ts
@@ -1,3 +1,4 @@
+import { EventEmitter } from 'node:events';
import { existsSync, unlinkSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
@@ -314,4 +315,16 @@ describe('Configuration', () => {
expect((config2 as any).customFlag).toBe(true);
});
});
+
+ it('does not change EventEmitter.defaultMaxListeners on import', async () => {
+ const original = EventEmitter.defaultMaxListeners;
+ EventEmitter.defaultMaxListeners = 7;
+ // The vitest setup already imported the module, so force it to be evaluated again
+ vitest.resetModules();
+ await import('../../packages/core/src/configuration.js');
+ const afterImport = EventEmitter.defaultMaxListeners;
+ EventEmitter.defaultMaxListeners = original;
+
+ expect(afterImport).toBe(7);
+ });
});