# DB2 - ui control Memory Leak Error

**URL:** <https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140>\
**Category:** Dashboard\
**Tags:** dashboard-2\
**Created:** [20 March 2025 23:34 UTC](https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140 "2025-03-20T23:34:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SandeepA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sandeepa/32/63225_2.png) [@SandeepA](https://discourse.nodered.org/u/SandeepA)\
**Post date:** [20 March 2025 23:34 UTC](https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140/1 "2025-03-20T23:34:03Z")

</div>

Hi ,

I am working on a flow on DB2 which uses ui control node in multiple places to show/hide groups.

Periodically, i find that the dashboard becomes unresponsive .  
And i see below error in the console.log of NR run.

```auto
21 Mar 04:44:28 - [info] [ui-base:XXXX] Disconnected 17FeqNVHwXGEK5CRAAAB due to transport close
(node:46476) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 disconnect listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
(node:46476) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 ui-control listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
21 Mar 04:45:39 - [info] Stopping modified nodes

```

While it says - what to do - not clear where this needs to be set.  
Any help appreciated.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 March 2025 06:02 UTC](https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140/2 "2025-03-21T06:02:05Z")

</div>

@SandeepA  
That warning is a known [issue](https://github.com/FlowFuse/node-red-dashboard/issues/1620) for both the ui-control an and ui-event nodes. They keep adding listeners to the [socket.io](http://socket.io) websocket for every node, instead of reusing a single listener. [Socket.io](http://Socket.io) gives that warning if more than 10 listeners are added.

To ged rid of that there are 2 options:

- Refactor the code to use one listener.
- Analyze whether all listeners are cleaned up correctly and increase the maximum allowed listener count

So it 'might' be a leak, but we don't know that yet.

It might in your case also be caused by other root causes, e.g. by pushing too much data to the ui-chart node.

Bart

---

<div class="post-metadata">

**Author:** ![SandeepA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sandeepa/32/63225_2.png) [@SandeepA](https://discourse.nodered.org/u/SandeepA)\
**Post date:** [21 March 2025 12:15 UTC](https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140/3 "2025-03-21T12:15:52Z")

</div>

> [@BartButenaers](#):
>
> Refactor the code to use one listener.

Let me try that.  
Where can increase max allowed listener count ?

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [21 March 2025 16:33 UTC](https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140/4 "2025-03-21T16:33:06Z")

</div>

> [@SandeepA](#):
>
> Where can increase max allowed listener count ?

Don't do this, just use link nodes to send the output of one ui-control to wherever you need it.

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [21 March 2025 17:04 UTC](https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140/5 "2025-03-21T17:04:05Z")

</div>

I assume it should be done once in a central code snippet, e.g. in the [ui-base](https://github.com/FlowFuse/node-red-dashboard/blob/main/nodes/config/ui_base.js) code. The `setMaxListener` function is documented [here](https://nodejs.org/api/events.html#emittersetmaxlistenersn).

Indeed like @Sean-McG mentions, _ **imho** _ you won't achieve much with this. You can use it in your local copy of the dashboard code. But I 'assume' it won't be accepted via a PR in the dashboard repo, unless you analyze in depth first whether all listeners are being cleaned up correctly. Otherwise you are allowing the system to keep on adding new listeners, but they 'might' not be cleaned up afterwards. In that case you would indeed introduce a leaking system. The result of the analysis might also be that all listeners are cleaned up correcly already by the dashboard code, and then there is no problem in increasing the max listener count.

But of course I might be completely mistaken...

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [21 March 2025 17:58 UTC](https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140/6 "2025-03-21T17:58:16Z")

</div>

It looks to me, after a very brief look at the code, that the [Socket.IO](http://Socket.IO) handling should be centralised under a single entity - perhaps a singleton class as I do it in UIBUILDER or maybe a runtime plugin instead? Then any D2 node could use the same [Socket.IO](http://Socket.IO) instance.

PS: Just noting that I think there is an outstanding bug in Node-RED's palette handling which doesn't like having a plugin and nodes in the same package. It all works but does not show the nodes in the palette manager, only the plugin. Only the palette manager is visually affected. But it is still annoying.

---

<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:** [20 April 2025 17:58 UTC](https://discourse.nodered.org/t/db2-ui-control-memory-leak-error/96140/7 "2025-04-20T17:58:41Z")

</div>

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