# Possible EventEmitter memory leak detected \[CommandEmitter\]

**URL:** <https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857>\
**Category:** General\
**Created:** [8 December 2022 11:30 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857 "2022-12-08T11:30:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [8 December 2022 11:30 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/1 "2022-12-08T11:30:33Z")

</div>

Greetings to all.

Accidentally launched Node-RED from the command line and found:

```auto
root@GigaIII-YN:/opt/etc/init.d$ ./S30node-red start0
root@GigaIII-YN:/opt/etc/init.d$ (node:11889) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 command listeners added to [CommandEmitter]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)

```

Studied the topics:

> [@Possible EventEmitter memory leak detected. Unknown (unfindable) node](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-unknown-unfindable-node/49114):
>
> Greetings. I am getting the following error pretty often in my cmd console: (node:66456) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 data listeners added to [SockJSConnection]. Use emitter.setMaxListeners() to increase limit I do not use subflows and can not find node 66465. I have done a text search in my flows.json and looked for that number in the search box in Node-RED. Both return zero results. Running node version 16.3.0 Node-RED 1.3.5 Any …

> [@Node --trace-warnings](https://discourse.nodered.org/t/node-trace-warnings/63728):
>
> At start my raspberry Pi4 I have this error: (node:1548) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 flows:started listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit (Use node --trace-warnings ... to show where the warning was created) Well, I don't understand how to use `node --trace-warnings ...` like this? node-red node --trace-warnings or how? Thank you ...

Got the details:

 ![Leaks](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d202637c105ce45a412398268089d7983256d878.jpeg)

But there is not enough knowledge to understand what is happening.  
Please help me figure it out.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [8 December 2022 12:48 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/2 "2022-12-08T12:48:34Z")

</div>

Hi @Yury

This is not directly related to Node RED.

The module that you have installed: **node-red-contrib-join-joaoapps**  
Is using a very common approach to event handling.

If subscriptions to events exceed a threshold, it will issue this warning.

either

- This is to be expected (it does indeed create a lot of subscriptions) or
- The module is not doing proper clean up after its been disposed/restarted

The developer of **node-red-contrib-join-joaoapps** will need to address this.

if the module is using it's own `EventEmitter` instance, the developer can opt to silence this warning, if its to be expected.

---

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [8 December 2022 13:51 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/3 "2022-12-08T13:51:57Z")

</div>

[marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)  
Thank you for the detailed answer.

How did you know that all the records belong to the same node?

Up to this point, I have not limited the number of this node and there are really about a lot of them. If I reduce all events to two nodes, will it reduce the number ?

Is why there have been no such messages for more than 2 years, but I noticed them only yesterday? Have security policies changed ?

And the last question is why do these warnings appear only when running from the command line, and they have never been in the log?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [8 December 2022 15:11 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/4 "2022-12-08T15:11:29Z")

</div>

> How did you know that all the records belong to the same node?

Its in the modules source code

> <https://github.com/joaomgcd/node-red-contrib-join-joaoapps/blob/334187d65456137f73e247073fb3f31cdd29a4f6/join-server.js#L9>

> Up to this point, I have not limited the number of this node and there are really about a lot of them. If I reduce all events to two nodes, will it reduce the number ?

I would have thought so, but the dev may be doing other events internally, that you cant control, if it still continues. It is just a warning and shouldn't always be treated as if its about to implode 😅

---

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [8 December 2022 16:49 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/5 "2022-12-08T16:49:13Z")

</div>

> [@marcus-j-davies](#):
>
> `var localStorage = new LocalStorage('./joinserver');`

Thanks for the information. Concerns from lack of Linux knowledge. More than 30 years with Windows. But NodeRed is so good that you have to learn Linux.

You were so kind as to provide a code snippet that I had to tinker with. For some reason that I don't understand,` var localStorage` doesn't know where the node is located. In order to solve the problem somehow, I manually write the full path to `new localStorage('./joinserver')`.  
And after each update, I restore it.  
Maybe there is some right way?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [8 December 2022 17:15 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/6 "2022-12-08T17:15:45Z")

</div>

The reason for the `CommandEmitter` warning is due to \>10 listeners on an event, if that is to be expected, then it can be ignored, if it is not, then it may be the fact the developer is not cleaning up the module after its disposed off - you need to submit a report to the developer to get it fixed.

The code snippet (from this module) was to answer...

> How did you know that all the records belong to the same node?

As it shows the creation of the `CommandEmitter`

The use of the below is nothing todo with it, and should be left as is (its not incorrect)

```auto
var LocalStorage = require("node-localstorage").LocalStorage
var localStorage = new LocalStorage('./joinserver');

```

---

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [8 December 2022 17:25 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/7 "2022-12-08T17:25:30Z")

</div>

> [@marcus-j-davies](#):
>
> you need to submit a report to the developer to get it fixed.

Ok

Yes, of course, these are completely different things. I just saw the familiar lines. Can I make a separate topic for this ?

> [@marcus-j-davies](#):
>
> As it shows the creation of the `CommandEmitter`
> 
> The use of the below is nothing todo with it, and should be left as is (its not incorrect)
> 
> ```auto
> var LocalStorage = require("node-localstorage").LocalStorage
> var localStorage = new LocalStorage('./joinserver');
> 
> ```

If you leave it as it is, then I get a crash NodeRED:

```auto
Welcome to Node-RED
===================

8 Dec 15:10:28 - [info] Node-RED version: v1.1.3
8 Dec 15:10:28 - [info] Node.js version: v16.16.0
8 Dec 15:10:28 - [info] Linux 4.9-ndm-4 mipsel LE
8 Dec 15:10:29 - [info] Palette editor disabled : npm command not found
8 Dec 15:10:29 - [info] Loading palette nodes
8 Dec 15:10:56 - [info] Dashboard version 2.23.4 started at /ui
8 Dec 15:11:00 - [warn] ------------------------------------------------------
8 Dec 15:11:00 - [warn] [node-red-contrib-join-joaoapps/join-server] ReferenceError: RED is not defined (line:11)
8 Dec 15:11:00 - [warn] ------------------------------------------------------
8 Dec 15:11:00 - [info] Settings file : /opt/lib/node-red_1/settings.js
8 Dec 15:11:00 - [info] Context store : 'memory' [module=memory]
8 Dec 15:11:00 - [info] Context store : 'mem_file' [module=localfilesystem]
8 Dec 15:11:00 - [info] User directory : /opt/lib/node-red_1
8 Dec 15:11:00 - [warn] Projects disabled : editorTheme.projects.enabled=false
8 Dec 15:11:00 - [info] Flows file : /opt/lib/node-red_1/flows_GigaIII-YN.json
8 Dec 15:11:00 - [info] Server now running at http://127.0.0.1:1881/
8 Dec 15:11:06 - [info] Waiting for missing types to be registered:
8 Dec 15:11:06 - [info] - join-server
8 Dec 15:13:45 - [info] Stopping flows
8 Dec 15:13:45 - [info] Stopped flows

```

It is important for me to understand:

1. this is a flaw of the author,
2. lack of my knowledge
3. or a feature of Node-RED as a NodeJS package?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [8 December 2022 17:33 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/8 "2022-12-08T17:33:26Z")

</div>

Ok,  
That makes more sense why you brought it up.

I would make another thread specific for that error.

As a module developer myself, I would say this may be a bug in the module ("this is a flaw of the author"), but if you are using Node RED as a module in its-self

> or a feature of Node-RED as a NodeJS package?

then there will likely be better folk around for that setup.  
I only run Node RED as a service not as child module.

---

<div class="post-metadata">

**Author:** ![Yury](https://avatars.discourse-cdn.com/v4/letter/y/f19dbf/32.png) [@Yury](https://discourse.nodered.org/u/Yury)\
**Post date:** [8 December 2022 17:43 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/9 "2022-12-08T17:43:17Z")

</div>

> [@marcus-j-davies](#):
>
> I only run Node RED as a service not as child module.

I also want NodeRed as a service, but I don't know how to do it.  
Node-RED is the most important thing.

In my case, today NodeRed is a NodeJS package, which itself is a package of system Entware. And this system is deployed on the Linux operating system, which runs on a home router.  
Which, of course, is very convenient and, most importantly, reliable. For 4 years, I have never had any NodeRed failures, not counting those caused by my inexperience.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 February 2023 17:43 UTC](https://discourse.nodered.org/t/possible-eventemitter-memory-leak-detected-commandemitter/71857/10 "2023-02-06T17:43:31Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
