bug in eventemitter2

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
piet66
Posts: 267
Joined: 04 Feb 2017 17:00

bug in eventemitter2

Post 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.
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v4.1.2 from 2023-10-18 03:34:26 +0300
piet66
Posts: 267
Joined: 04 Feb 2017 17:00

Re: bug in eventemitter2

Post 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.
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v4.1.2 from 2023-10-18 03:34:26 +0300
User avatar
PoltoS
Posts: 7579
Joined: 26 Jan 2011 19:36

Re: bug in eventemitter2

Post 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.
piet66
Posts: 267
Joined: 04 Feb 2017 17:00

Re: bug in eventemitter2

Post 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
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v4.1.2 from 2023-10-18 03:34:26 +0300
User avatar
PoltoS
Posts: 7579
Joined: 26 Jan 2011 19:36

Re: bug in eventemitter2

Post 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.
piet66
Posts: 267
Joined: 04 Feb 2017 17:00

Re: bug in eventemitter2

Post 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?
Raspberry Pi 3 Model B Rev 1.2
Raspbian GNU/Linux 10 (buster, 32bit)
RaZberry by Z-Wave.Me ZW0700 7.20.00 07.38/1766938484 1025/257
Z-Way version v4.1.2 from 2023-10-18 03:34:26 +0300
User avatar
PoltoS
Posts: 7579
Joined: 26 Jan 2011 19:36

Re: bug in eventemitter2

Post by PoltoS »

I think only by inspecting internal structures of if or by adding a console.log to the place where it is checked ;)
Post Reply