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

MaxListenersExceededWarning: Possible EventTarget memory leak detected. 101 abort listeners added to [AbortSignal] #47449

Closed
fawazahmed0 opened this issue Apr 6, 2023 · 6 comments · Fixed by nodejs/undici#2063 or nodejs/undici#3372

Comments

@fawazahmed0
Copy link

fawazahmed0 commented Apr 6, 2023

Version

v19.8.1

Platform

Microsoft Windows NT 10.0.22000.0 x64

Subsystem

No response

What steps will reproduce the bug?

const { setMaxListeners } = require('events')

const generalController = new AbortController();
setMaxListeners(Infinity, generalController.signal)

async function begin(){

    for(let i=0;i<2000;i++)
        fetch('https://1.1.1.1/cdn-cgi/trace', { signal: generalController.signal })

}
begin()

How often does it reproduce? Is there a required condition?

This MaxListenersExceededWarning is shown in v19.8.1, it did not appear in v19.5

What is the expected behavior? Why is that the expected behavior?

The MaxListenersExceededWarning should not appear as setMaxListeners is already set to Infinity in the code above

What do you see instead?

(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 101 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 102 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 103 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 104 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 105 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 106 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 107 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 108 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 109 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 110 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 111 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 112 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 113 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 114 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 115 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:13080) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 116 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit

Additional information

No response

@fawazahmed0
Copy link
Author

Related nodejs/undici#1910

@debadree25
Copy link
Member

I think this would be solved once #47039 lands on a release line, undici can then set the max value to the value of max event listeners of the given signal I believe
cc @KhafraDev

@fawazahmed0
Copy link
Author

This warning message still seems to be there in v19.9.0

@clickingbuttons
Copy link

Still occurring in v21.6.1 . Was there a regression?

@fawazahmed0
Copy link
Author

Yes, this bug still exists

@flevi29
Copy link

flevi29 commented Mar 8, 2024

Not fixed. Node.js v20.11.0. "undici": "^6.7.1"

abort_test.mjs

import { setMaxListeners } from "node:events";
import { fetch } from "undici";

const { signal } = new AbortController();
setMaxListeners(110, signal);

for (let i = 0; i < 110; i += 1) {
  fetch("https://1.1.1.1/cdn-cgi/trace", { signal }).catch(console.error);
}
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 101 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 102 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 103 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 104 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 105 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 106 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 107 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 108 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 109 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit
(node:18748) MaxListenersExceededWarning: Possible EventTarget memory leak detected. 110 abort listeners added to [AbortSignal]. Use events.setMaxListeners() to increase limit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants