Skip to content
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

Listener remotedeviceready not removed when peer disconnects #375

Open
ScottErholm opened this issue Apr 19, 2019 · 2 comments
Open

Listener remotedeviceready not removed when peer disconnects #375

ScottErholm opened this issue Apr 19, 2019 · 2 comments

Comments

@ScottErholm
Copy link

Listeners on 'remotedeviceready' are never removed when the initiating peer disconnects, causing memory leak. MaxListenersExceededWarning issued after default 10 listeners are enabled.

Somewhat related to #294 and could be fixed at the same time as that.

@AdamMagaluk
Copy link
Collaborator

Do you have a quick example you can provide?

@ScottErholm
Copy link
Author

Yep, in runtime.js in the 'observe' method, there are two places where the listener is created:

self.on(peer.name + '/remotedeviceready', function(device) { ... }

But that listener is never removed, even if the peer disconnects. Then if the same peer reconnects, a new listener is registered. The listeners just keep building up.

I tested moving the listener function out to a function named 'matchDevice' and then subscribing to a disconnect:

self.pubsub.subscribe('_peer/disconnect', function(ev, data) {
  if (data.peer.name === query.server) {
    self.removeListener(data.peer.name + '/remotedeviceready', matchDevice);
  }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants