-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. #31
Comments
Thanks for the report! I'm not sure what could be causing this off the top of my head. Would you mind posting a reproducible test case? |
There is no reproducible test case ATM. We have an application that uses 5-7 MQTT topics and sends data between then with some processing. So a node application opens 5-7 MQTT connections to a hub, receives messages using Now we refactored application and after receiving same 300 packets per second packets we send to intermediary topics much less data (approx. 10% of incoming packets) and problem disappeared for now but its root cause is still unclear. |
Weird. I'm not sure if this'd be an issue with async-mqtt specifically or if it's MQTT.js in general. It might be a good idea to check the issues there to see if anyone has had the same problem. I'll leave this open for now, but I don't have bandwidth to investigate without a reproducible test case. 😁 |
MaxListenersExceededWarning I believe is a node.js events warning when you attach 10+ listeners to an event. https://nodejs.org/api/events.html#events_emitter_setmaxlisteners_n MQTT.js So a solution is to set maxListeners to infinity if you are sure there is no memory leak.
IMO this should only be set in end-user code. Not in the library as it is there to catch possible memory leaks. |
@fijiwebdesign I already tried to tweak listeners count a week ago and added logging like this:
It properly reports number of send and received packets but listenerCount and ATM we refactored our data processing, added MQTT packets filtering and decreased traffic from 300 packets/second to approx 40 packets/second. With this decreased load same MQTT code without outages, so I think the problem is related somehow to the incoming data rate. I will try to prepare isolated test case for this problem later. |
Hello, first of all thank you for your amazing work. This problem it is also happening with me. My script is simple, i do a query on a DB and then for every record retrieved i publish it. My script: let collectionObject = db.collection(config.mongodb.collection)
let queryResult = await collectionObject.find().limit(2000).toArray()
console.log('Mongo Collection Query');
asyncClient.setMaxListeners(0)
await Promise.all(queryResult.map(async (doc) => {
let payload = `${doc.message};${doc.datetime};`
try {
await asyncClient.publish(doc.topic, payload)
} catch (err) {
console.error(err);
process.exit(1)
}
finally {
await collectionObject.deleteOne({ _id: doc._id })
}
})) As you can see, i even tried using setMaxListeners(0), but it didn't work. When i run this script it with --trace-warnings i get: My only work around by now was limiting the query on DB. I hope that this will help you guys to solve the problem, thank you, |
@GuilhermeDaniluski It could be that somewhere internally in the MQTT.js library it might be adding a listener when you I don't think this is a memory leak that you should be worrying about or anything, though. If you want to control the event listener list of internal streams, that'd probably be an issue for the MQTT.js repo that this library depends on. |
I started to see in logs following warning, but it's unclear what mat cause it. Do you have any ideas?
The text was updated successfully, but these errors were encountered: