y-js / y-websockets-client

Websocket connector for Yjs (Browser/Node client)
20 stars 10 forks source link

Possible Memory Leak Issue? #9

Open emreeren opened 6 years ago

emreeren commented 6 years ago

App was working in the background and I was doing something else so I'm not %100 sure if it is an issue or not. Just wanted to let you know.

image

emreeren commented 6 years ago

OK I think this is not a memory leak issue. I'm hosting server on heroku as shown on the tutorial and it happens when I try to restart server manually while there is an existing client connection to server. When it tries to restore the connection it tries to sync data multiple times and seems like connection count increases on each step of restoration.

2018-04-04_12-09-33

Having that much "disconnecting" rows in the log appears like already failed connections still tries to sync. It keeps increase until chrome stops it because of out of memory error. If I reload the application before it crashes it simply connects and syncs fine as it always do.

Here another screenshot of multiple sync attempts for the current user.

image

I hope it gives an idea. I also enabled IndexedDB. Can it be the reason of the issue? Also data size client needs to upload to server is around 8MB's and I'm behind a slow upload speed connection.

emreeren commented 6 years ago

I debugged it today and found it registers yjsEvent and disconnect events multiple times as _onConnect gets called on each reconnect attempt. Changing _onDisconnect to unregister these events seems like solves the issue for me.

this._onDisconnect = function (peer) {
    socket.off('disconnect', self._onDisconnect)
    socket.off('yjsEvent', self._onYjsEvent)
    Y.AbstractConnector.prototype.disconnect.call(self)
}