-
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
Memory Leak in ZettaHttpServer - PeerSockets #294
Comments
@AdamMagaluk @mdobson Thoughts? This is currently an issue in our custom cloud deployment. @landlessness, you may be experiencing some ill effects from this, too. |
A workaround, in the meantime, implementing Option 1 above: zetta()
.name('cloud')
.use(function(runtime) {
runtime.pubsub.subscribe('_peer/disconnect', function(ev, msg) {
delete runtime.httpServer.peers[msg.peer.name];
});
})
.listen(process.env.PORT || 1337); |
@kevinswiber The main (possibly only reason, I forget) we are keeping the peer_sockets around is to keep the list of event subscriptions from clients/apps to that peer and subscribe to them when they reconnect. Of course this can be done differently by using the event_broker or other internals to get a list of subscriptions for that peer. We could also delete the peer once all of it's subscriptions are gone (clients disconnecting), though I don't think that would ever be the case for our deployment. |
@AdamMagaluk Thanks for the assessment. Let's abstract that away. What can we do about unbounded growth on leftover subscriptions? Do we need to institute a timeout between the lack of availability of connected device streams and the subscriptions to those streams? Is there a straightforward solution? Perhaps we could use a circular buffer that holds dead subscriptions and starts dropping them on overflow? Unbounded growth is not only hurting memory consumption; it's also an attack vector. |
@kevinswiber I think the best approach would be to delete the peer_socket from In this case zetta would only keep subscriptions and peers when they are currently connected. We would that just have to worry about an unbounded number of peers connecting, clients connecting, and subscriptions from clients but that solved pretty easily by some limits. I think it would be pretty straightforward, may take a bit code and figuring out how to access the proper data but it's all there. |
When one Zetta peer connects to another, the receiver stores a
PeerSocket
in itsZettaHttpServer#peers
object. When the initiating peer disconnects, itsPeerSocket
remains on the receiving peer. This was likely an intentional performance optimization for use cases that only ever have a few of the same peers connecting. In scenarios where hundreds, perhaps thousands of peers are connecting, the receiving peer'sZettaHttpServer#peers
object continues to grow. Some of these peers may disconnect and never return.We have a few options to address this:
delete
the peer fromZettaHttpPeers#peers
on_peer/disconnect
PeerSocket
instances. Prune this buffer on an interval.The text was updated successfully, but these errors were encountered: