Page 1 of 1

bug in eventemitter2

Posted: 17 Dec 2023 19:11
by piet66
Hello,
I need someone who knows what's going on:

There seems to be a bug in eventemitter2. Sometimes it throws an exception together with its warning

Code: Select all

[2023-12-17 14:48:07.626] [I] [core] (node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit. 11
[2023-12-17 14:48:07.647] [E] [core] Callback execution error: TypeError: undefined is not a function
    at EventEmitter.on [as addListener] (automation/lib/eventemitter2.js:392:29)
    at _.extend.on (automation/classes/DevicesCollection.js:203:37)
I found this warning printed at 2 places in the code. On one place it throws this exception.

The text proposes to use emitter.setMaxListeners() to increase the limit. Does anybody know how to do that? I want to get rid of this exception.

Re: bug in eventemitter2

Posted: 17 Dec 2023 19:31
by piet66
I just have found this:
https://forum.z-wave.me/viewtopic.php?f ... er2#p89740

However, the answer is unsatisfactory. On the one hand, I am of the opinion that the program must not throw an exception with a warning. Either it's a warning, then the program has to continue. Or it's a severe error, then it needs an error message.
On the other hand, the user should not fiddle around in the code.

Re: bug in eventemitter2

Posted: 21 Dec 2023 04:05
by PoltoS
The error comes from the third-party EventEmitter library we use. It has a limit on the max number of subscriptions. I'm not sure why they do... We use a pretty high number of events, but it looks you need more. You can add it on your side or make a PR in our Git Hub repo so we start using a bigger number.

Re: bug in eventemitter2

Posted: 21 Dec 2023 11:40
by piet66
Thank you for the explanation.

The main problem is, in my opinion, that the limit is fixed in the code. And if the user increases it in the code, it will be overwritten at the next update again.

And if you set the value higher by default, it may be too small again at some point

Re: bug in eventemitter2

Posted: 11 Jan 2024 18:08
by PoltoS
Let's first try how many do you need and maybe we increase it to that value in the main branch. We have already increased it a few years ago.

Re: bug in eventemitter2

Posted: 12 Jan 2024 10:12
by piet66
Isn't is possible to add defaultMaxListeners as an option to config.xml and set it during server start?

I have tried several increasing values to find the right one for me. But it was very time-consuming, since every time a server restart is necessary. And every time it was too small. In the end, I just set it to 50. It's probably far too high, but at some point I didn't have enough motivation.

Is there a way to find out how much of it the eventemitter really uses?

Re: bug in eventemitter2

Posted: 19 Jan 2024 19:36
by PoltoS
I think only by inspecting internal structures of if or by adding a console.log to the place where it is checked ;)