diff --git a/lib/web/fetch/request.js b/lib/web/fetch/request.js index bc436aa9705..51bb2b3ab14 100644 --- a/lib/web/fetch/request.js +++ b/lib/web/fetch/request.js @@ -28,7 +28,7 @@ const { webidl } = require('./webidl') const { URLSerializer } = require('./data-url') const { kConstruct } = require('../../core/symbols') const assert = require('node:assert') -const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners } = require('node:events') +const { getMaxListeners, setMaxListeners, defaultMaxListeners } = require('node:events') const kAbortController = Symbol('abortController') @@ -429,8 +429,6 @@ class Request { // This is only available in node >= v19.9.0 if (typeof getMaxListeners === 'function' && getMaxListeners(signal) === defaultMaxListeners) { setMaxListeners(1500, signal) - } else if (getEventListeners(signal, 'abort').length >= defaultMaxListeners) { - setMaxListeners(1500, signal) } } catch {} diff --git a/test/fetch/max-listeners.js b/test/fetch/max-listeners.js new file mode 100644 index 00000000000..36e4fef101b --- /dev/null +++ b/test/fetch/max-listeners.js @@ -0,0 +1,16 @@ +'use strict' + +const { setMaxListeners, getMaxListeners, defaultMaxListeners } = require('events') +const { test } = require('node:test') +const assert = require('node:assert') +const { Request } = require('../..') + +test('test max listeners', (t) => { + const controller = new AbortController() + setMaxListeners(Infinity, controller.signal) + for (let i = 0; i <= defaultMaxListeners; i++) { + // eslint-disable-next-line no-new + new Request('http://asd', { signal: controller.signal }) + } + assert.strictEqual(getMaxListeners(controller.signal), Infinity) +})