MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 scanStop listeners added. Use emitter.setMaxListeners() to increase limit #22

Hi

I have a flow in node red that after some time stops initialising the BLE scanner node. I have a delay loop activating the scanner (noble node) switching between true and false at a set interval. Everything works well initially but after a while the scan node remains on 'started' state and nothing updates. The node red console indicates "MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 scanStop listeners added. Use emitter.setMaxListeners() to increase limit noble node red."

I have read that this can be changed in the node js but don't know what file I need to change. Any help would be great

Thanks

Which node are you using to do the scanning? The issue will likely be inside that node and for its author to fix.

I posted this in the github but didnt get a reply. I dont know what else I can use or if I can change the authors script to increase the max listeners.

Any help would be great :slight_smile:

I wouldn’t hold your breath waiting for a response. That node looks like it has been abandoned. Last update was over 3 years ago.

I'm slightly surprised that the node stops working, but I haven't looked at the code. The message is only a warning, not an error, but there may be something that responds to it and shuts the node down. It's less likely that you are really running out of memory, because the symptoms would be worse.

The immediate problem could be fixed by doing as the message says:

(The default limit is 10 listeners, which is why the node complains when the count reaches 11.)

If the warning persists for large values of setMaxListeners, the node may not be doing its housekeeping properly and leaking memory as a result.

Where do we set this emitter.setMaxListeners() thing ?

It has to be set in the node that is emitting the event, which means editing the source of the node that is producing them. But as noted it's normally just a warning.

1 Like

I get these warnings too.

click me

@WhiteLion this is a generic warning, so by itself, it doesn't give us enough information to help. In your flows, have you got more than ten instances of any particular contrib node?

I think I do have. I realy rape node-red: my (light) switch flow (I ve 12 of them) has 166 nodes .... about 20 dashbord about 80 function nodes with 3 - 40 lines of code each.... some is debug, delay, subflow ...

this is how it looks like

Mos would say its a bad use of node-red ... but I dont care, it works for me :slight_smile:

Did you find where to set this ? I have the same trouble and I do not find where to define it... Thank you !

Sorry to resurrect this thread, but I found that one of my nodes suffers from the same culprit. If I know which node causes it, that would really help me forward. This is the output from my log:

(node:17) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connecting listeners added. Use emitter.setMaxListeners() to increase limit
(node:17) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connect listeners added. Use emitter.setMaxListeners() to increase limit
(node:17) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit

How can I find what node:17 is?

Well. one way would be to disable parts of your flow to narrow down the suspect. You could also add a catch node connected to a dbug node (set to display the 'complete msg object') and see if it gives any more information.

What nodes are you using in the flow?

Thank you for your response.

Disabling parts of my flow looks like a lot of work, given the many number of tabs involved. I think it's especially hard because there seems no consistent way to reproduce the warning messages in my case, so maybe it's not a big problem after all?

Anyhow, I'm using lots of modules, so posting the list here might help cross-reference it with others to narrow down a (or more) possible suspects:

"md5": "^2.2.1",
"node-red-contrib--cron-pkjq": "0.0.1",
"node-red-contrib-bigtimer": "~2.7.3",
"node-red-contrib-bool-gate": "~1.0.2",
"node-red-contrib-cast": "~0.2.17",
"node-red-contrib-castv2": "~4.0.3",
"node-red-contrib-eiscp": "0.3.3",
"node-red-contrib-elasticsearch-jupalcf": "~1.1.14",
"node-red-contrib-harmony-websocket": "~2.2.6",
"node-red-contrib-huemagic": "~3.0.0",
"node-red-contrib-influxdb": "~0.5.4",
"node-red-contrib-json": "~0.2.0",
"node-red-contrib-moment": "~4.0.0",
"node-red-contrib-msg-speed": "~2.0.0",
"node-red-contrib-openhab3": "^1.3.3",
"node-red-contrib-simpletime": "~2.10.0",
"node-red-contrib-smb": "~1.2.0",
"node-red-contrib-solaredge": "~0.1.0",
"node-red-contrib-throttle": "~0.1.6",
"node-red-contrib-timed-counter": "0.0.4",
"node-red-contrib-timeframerlt": "~0.3.1",
"node-red-node-aws": "~0.2.0",
"node-red-node-darksky": "~0.1.19",
"node-red-node-email": "~1.8.3",
"node-red-node-random": "~0.3.1",
"node-red-node-rbe": "~0.2.9",
"regression-fork-norounding": "1.4.0-11",
"thingzi-logic-timers": "~1.1.3",
"trend": "0.3.0"

Hi there!

I have the same issue using docker image of Node Red and version 2.0.5.

Does anyone figured it out?.

Regards!

Same here did you solve the issue?

Hello,
I'm reviving this topic to get a better understanding of this Error if it is an error.

(node:2072002) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 opened listeners added to [WebSocketListenerNode]. Use emitter.setMaxListeners() to increase limit
0|Demo_iLab  | 
(node:2072002) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 erro listeners added to [WebSocketListenerNode]. Use emitter.setMaxListeners() to increase limit
0|Demo_iLab  | 
(node:2072002) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 closed listeners added to [WebSocketListenerNode]. Use emitter.setMaxListeners() to increase limit

My understanding :

  • I have a WebSocket "Input Node" that forward messages along the pipes
  • I have a SubFlow "Send Message" that wrap a WebSocket "Output Node" to reply custom messages
  • I use 100 instances of this subflow to send messages back to the user. (I have a session mechanics that retrieve the socket context and reply)

This mechanics is really clean and works well for years along Node-Red various version. But I always get this error in the logs and I wondering if I should increase this max limit ?

The Arrows targets a parent's parent's flow that use my websocket subflow.

What happenend If I use that cool Subflow Node in many flows and suflows ? Is it reused or duplicated ? I assume it is duplicated and that would explain this warning ?

Is it a problem ? May be for many concurent messages ?

Every node in a subflow is a unique instantiated node.

If you have 10 nodes in a subflow and you have 100 instances of that subflow, you have 1000 nodes. If you use "full deploy" mode, then 1000 nodes get destroyed and re-created (and all of the internal connections they create etc etc). It is common to see slowdowns when working with large numbers of subflows.

If you have subflows in subflows, then this count starts getting to crazy numbers.


Often, there is no need for a subflow. for example, using the link-call node can be a better fit and will not have the same issue.

PS: I rarely use subflows. I often use link-call to create subroutines instead.

2 Likes

Thanks @Steve-Mcl !

In my case I use a lot of Subflow because I build a reusable framework (and upgrade are simple)

  1. Top Node is a WebChat Node
  2. Sub Node is the LLM component used by WebChat
  3. Sub Sub Node is the Model Manager

This exemple, let buid project focus on different layers according to the objectives.

I don't find deploy very slow in my case. It's almost instant.

In fact I use Subflow as reusable components with parameters and with latest Node-RED version and env var it's really clean.

Question :
According to your description, if I have, let's say, 50? Websocket Output bind to the same output.

  • Is it a problem ?
  • I assume it is the reason of the warning. Should I increase it ? What are the side effect ?

(Yes I could create a link node in that case but it will provide a bad UX)

@Steve-Mcl is not referring to link nodes, but to link-call nodes, which is a different concept that makes reusable flows possible, without cluttering the UI as it will exist as a single node within the flow.

eg.

It is one of the best underrated things in node-red imo.

3 Likes