yjs / y-websocket

Websocket Connector for Yjs
https://docs.yjs.dev/ecosystem/connection-provider/y-websocket
MIT License
508 stars 258 forks source link

Memory leaks in yjs websocket utils implementation? #142

Open sbavoma opened 1 year ago

sbavoma commented 1 year ago

I have a editor application made using yjs websocket server implementation. The code is strictly used as is from the library and it works pretty well. Until now I didn't had any monitoring tools in place to observe its behaviour but lately I have seen RAM piling up with memory and this is a bit surprising since the application gets around 300-500 traffic on a good day. Is there anyway to properly debug this like some library to get heap snapshots or is this issue pre-existent cause I saw few threads before but they were fixed. Is something to be done to clear all the event listeners and handlers.

I also see some weird logs that I get in my pm2 service regarding service restarts when there are lot of connections. It seems yjs has some soft limit on no of event emitters/handlers need to know how this can be tackled!

some error logs eg:

[yjs] Tried to remove event handler that doesn't exist.
[yjs] Tried to remove event handler that doesn't exist.
[yjs] Tried to remove event handler that doesn't exist.
[yjs] Tried to remove event handler that doesn't exist.
[Function: Error] { stackTraceLimit: 10, prepareStackTrace: undefined }
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
[Function: Error] { stackTraceLimit: 10, prepareStackTrace: undefined }
[Function: Error] { stackTraceLimit: 10, prepareStackTrace: undefined }
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
[Function: Error] { stackTraceLimit: 10, prepareStackTrace: undefined }
[Function: Error] { stackTraceLimit: 10, prepareStackTrace: undefined }
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
[Function: Error] { stackTraceLimit: 10, prepareStackTrace: undefined }
[Function: Error] { stackTraceLimit: 10, prepareStackTrace: undefined }
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
[Function: Error] { stackTraceLimit: 10, prepareStackTrace: undefined }
[yjs] Tried to remove event handler that doesn't exist.
[yjs] Tried to remove event handler that doesn't exist.
[yjs] Tried to remove event handler that doesn't exist.
[yjs] Tried to remove event handler that doesn't exist.

Attached a ss of the mem leak... Screenshot 2023-06-26 at 2 46 38 AM

jiangxiaoqiang commented 11 months ago

did you fixed this issue? @sbavoma