Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't override user defined MaxListeners #3372

Merged
merged 10 commits into from
Jun 26, 2024
4 changes: 1 addition & 3 deletions lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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 {}

Expand Down
13 changes: 13 additions & 0 deletions test/fetch/max-listeners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'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++) { new Request('http://asd', { signal: controller.signal }) }

Check failure on line 11 in test/fetch/max-listeners.js

View workflow job for this annotation

GitHub Actions / Lint

Do not use 'new' for side effects
fawazahmed0 marked this conversation as resolved.
Show resolved Hide resolved
assert.strictEqual(getMaxListeners(controller.signal), Infinity)
})
Loading