Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzlopak committed Nov 13, 2024
1 parent d1d8686 commit 8244a70
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const { getMaxListeners, setMaxListeners, defaultMaxListeners } = require('node:

const kAbortController = Symbol('abortController')

// This is only available in node >= v19.9.0
const hasGetMaxListeners = typeof getMaxListeners === 'function'

const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
signal.removeEventListener('abort', abort)
})
Expand Down Expand Up @@ -424,15 +427,16 @@ class Request {
const acRef = new WeakRef(ac)
const abort = buildAbort(acRef)

// Third-party AbortControllers may not work with these.
// See, https://github.com/nodejs/undici/pull/1910#issuecomment-1464495619.
try {
// If the max amount of listeners is equal to the default, increase it
// This is only available in node >= v19.9.0
if (typeof getMaxListeners === 'function' && getMaxListeners(signal) === defaultMaxListeners) {
setMaxListeners(1500, signal)
}
} catch {}
if (hasGetMaxListeners) {
// Third-party AbortControllers may not work with these.
// See, https://github.com/nodejs/undici/pull/1910#issuecomment-1464495619.
try {
// If the max amount of listeners is equal to the default, increase it
if (getMaxListeners(signal) === defaultMaxListeners) {
setMaxListeners(1500, signal)
}
} catch {}
}

util.addAbortListener(signal, abort)
// The third argument must be a registry key to be unregistered.
Expand Down

0 comments on commit 8244a70

Please sign in to comment.