-
Notifications
You must be signed in to change notification settings - Fork 114
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
EventEmitter Memory Leak in Event Broker #351
Comments
Welp, that was wrong. https://github.com/zettajs/zetta/blob/master/lib/event_broker.js#L322 // Unsubscribe to all subscriptions if the client disconnects
client.on('close', function() {
Object.keys(unsubscriptions).forEach(function(subscriptionId) {
unsubscriptions[subscriptionId].forEach(function(unsubscribe) {
unsubscribe();
});
delete unsubscriptions[subscriptionId];
})
}); |
@kevinswiber or @AdamMagaluk Any insights? I'm not sure what's going on in this unit test that causes a failure (https://travis-ci.org/zettajs/zetta/jobs/248924395). From what I can tell, the created I don't understand what the additional "close" handler added on each subscription is accomplishing (and why the unit test fails when it's removed). |
I've got it. What I was missing was the difference between Having this fixed is important because we've got a custom Node Red node for creating topic subscriptions. Underneath it is a single, long-lived socket connection over which subscriptions are managed. New nodes, simple UI changes of existing nodes, updating topics of existing nodes, etc. will ALL cause subscriptions over the socket. Eventually the number of "close" event listeners added to the client would get out of control. |
Issue
For every subscription created over the same socket, a "close" event handler is added to the same socket instance. After 11 subscriptions, this triggers Node's warning of a possible memory leak.
Source
lib/event_broker.js
https://github.com/zettajs/zetta/blob/master/lib/event_broker.js#L125
Steps to Reproduce:
(node:7108) Warning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit
The text was updated successfully, but these errors were encountered: