Skip to content

Commit

Permalink
Merge branch 'main' into fix-vary
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 authored Feb 7, 2025
2 parents 37262cf + d685d38 commit c05fce9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
31 changes: 20 additions & 11 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>Node.js Undici</title>
Expand All @@ -9,6 +10,7 @@
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify@4/lib/themes/vue.css">
<link rel="icon" type="image/png" href="https://nodejs.org/static/images/favicons/favicon.png" />
</head>

<body>
<div id="app"></div>
<script>
Expand All @@ -32,6 +34,11 @@
noCompileLinks: [
'benchmarks/.*'
],
copyCode: {
buttonText: 'Copy Code',
errorText: 'Error',
successText: 'Copied',
},
relativePath: true,
markdown: {
renderer: {
Expand Down Expand Up @@ -73,6 +80,7 @@
<!-- Docsify v4 -->
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script>
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/search.min.js"></script>
<script src="https://unpkg.com/docsify-copy-code@3"></script>
<script type="module">
import mermaid from "//cdn.jsdelivr.net/npm/mermaid@10.8.0/+esm";
mermaid.initialize({ startOnLoad: true });
Expand All @@ -81,18 +89,18 @@
<script>
const plugin = (config) => (hook) => {
hook.afterEach((html, next) => {
const container = document.createElement('div');
container.innerHTML = html;
const container = document.createElement('div');
container.innerHTML = html;

const elements = container.querySelectorAll('pre[data-lang=mermaid]')
for (const element of elements) {
const replacement = document.createElement('div');
replacement.textContent = element.textContent;
replacement.classList.add('mermaid');
element.parentNode.replaceChild(replacement, element);
}
const elements = container.querySelectorAll('pre[data-lang=mermaid]')
for (const element of elements) {
const replacement = document.createElement('div');
replacement.textContent = element.textContent;
replacement.classList.add('mermaid');
element.parentNode.replaceChild(replacement, element);
}

next(container.innerHTML);
next(container.innerHTML);
});

hook.doneEach(() => mermaid.run(config));
Expand All @@ -104,4 +112,5 @@
window.$docsify.plugins.push(plugin(window.$docsify.mermaidConfig || { querySelector: ".mermaid" }));
</script>
</body>
</html>

</html>
21 changes: 12 additions & 9 deletions lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {

const dependentControllerMap = new WeakMap()

let abortSignalHasEventHandlerLeakWarning

try {
abortSignalHasEventHandlerLeakWarning = getMaxListeners(new AbortController().signal) > 0
} catch {
abortSignalHasEventHandlerLeakWarning = false
}

function buildAbort (acRef) {
return abort

Expand Down Expand Up @@ -424,15 +432,10 @@ 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 the max amount of listeners is equal to the default, increase it
if (abortSignalHasEventHandlerLeakWarning && getMaxListeners(signal) === defaultMaxListeners) {
setMaxListeners(1500, signal)
}

util.addAbortListener(signal, abort)
// The third argument must be a registry key to be unregistered.
Expand Down
3 changes: 2 additions & 1 deletion test/fetch/long-lived-abort-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const http = require('node:http')
const { fetch } = require('../../')
const { once } = require('events')
const { once, setMaxListeners } = require('node:events')
const { test } = require('node:test')
const { closeServerAsPromise } = require('../utils/node-http')
const { strictEqual } = require('node:assert')
Expand Down Expand Up @@ -30,6 +30,7 @@ test('long-lived-abort-controller', { skip: true }, async (t) => {
})

const controller = new AbortController()
setMaxListeners(1500, controller.signal)

// The maxListener is set to 1500 in request.js.
// we set it to 2000 to make sure that we are not leaking event listeners.
Expand Down

0 comments on commit c05fce9

Please sign in to comment.