OpenHausIO / backend

HTTP API for the OpenHaus SmartHome/IoT solution
https://docs.open-haus.io
6 stars 2 forks source link

components `.found()` method could create event emitter memory leak #498

Open mStirner opened 1 week ago

mStirner commented 1 week ago
(node:76125) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 add listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:592:17)
    at EventEmitter.addListener (node:events:610:10)
    at C_DEVICES.found (/home/marc/projects/OpenHaus/backend/system/component/class.component.js:790:21)
    at device (/home/marc/projects/OpenHaus/backend/plugins/cf9e3660-e59e-4b4d-823a-330d4a5dc9b2/index.js:15:23)
    at new Promise (<anonymous>)
    at /home/marc/projects/OpenHaus/backend/plugins/cf9e3660-e59e-4b4d-823a-330d4a5dc9b2/index.js:14:30
    at init (/home/marc/projects/OpenHaus/backend/components/plugins/class.plugin.js:160:33)
    at module.exports (/home/marc/projects/OpenHaus/backend/plugins/cf9e3660-e59e-4b4d-823a-330d4a5dc9b2/index.js:2:12)
    at Plugin.start (/home/marc/projects/OpenHaus/backend/components/plugins/class.plugin.js:181:80)

This is per se not a error/issue. The more often .found() is used on a component item, the more event listeners are attached to the add event.

How to increase/set the maximal allowed listeners? Number of Plugins + 2?

Or disable it the warning for the event emitter?

mStirner commented 1 day ago

This is obsolete when plugins run in separate worker threads/child processes. See #6