node-mi-flora
node-mi-flora copied to clipboard
Possible EventEmitter memory leak detected
I am using this component with homebridge-mi-flower-care. After some time this error appears in the log and no updates are received subsequently:
(node) warning: possible EventEmitter memory leak detected. 11 servicesDiscover listeners added. Use emitter.setMaxListeners() to increase limit.
Do you have any idea?
Maybe it is related to the following issues: https://github.com/noble/noble/issues/480
Additionally. Why are you missing noble.stopScanning();
in line 109ff. The demo suggests:
if (state === 'poweredOn') {
noble.startScanning();
} else {
noble.stopScanning();
}
Third related question. In The demo the call stopScanning
in discover, such as:
...
noble.on('discover', function(peripheral) {
// we found a peripheral, stop scanning
noble.stopScanning();
...
Why is this missing here?
Instead of deciding when to start or stop scanning inside the library, I just handoff this job to the library user. There is a delegated method called stopScanning
here which does exactly what you send. In this way, you can decide when to start or stop related to your usage. I also mentioned it in the readme under the basic usage.
For the first question related to memory leak, I don't have clue right now. I haven't seen it before. I'll try to reproduce but would be nice if you could try the suggested branch in the thread and give some feedbacks.
I have the same issue. On my mac adapter state is unknown
, so library won't work. I've added logging of the noble.state
:
node /usr/local/lib/node_modules/node-mi-flora/examples/basic.js
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
every 15 seconds, rescan devices
unknown
(node:34922) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 stateChange listeners added. Use emitter.setMaxListeners() to increase limit