Should I monitor if there are sockets that haven't been accessed for a long time #4289
-
I know that the socket client has a disconnect() method, but this method does not execute when the browser is manually closed. When I create many namespce to correspond to different socket connections, and there is no listening to the client's disconction(), is there a possibility that my memory will overflow? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi! The server will automatically detect when the client has left: either when the WebSocket connection is closed (right away), or when the heartbeat mechanism fails (may take up to 45 seconds by default). So you shouldn't have to monitor for zombie connections. |
Beta Was this translation helpful? Give feedback.
-
As soon as the heartbeat mechanism fails. I want to make a db call. Is that Possible? How can I achieve that? I have a chat application. I have to handle online or offline status of a user. The way I am handling when the user is online is as soon as connection is getting established I am making a db call and updating the userSchema with online value as true . this is my sample userSchema {
"clientId": "963254",
"userId": "123456",
"__v": 0,
"lastActivity": {
"$date": "2024-03-12T12:34:02.746Z"
},
"online": true,
"socketIds": [
"yueeyyedtehbdv",
"yeeeeeeeeeeee"
]
} I want to detect heartbeat failures. Upon heartbeat failure, I will trigger a database call to update the online field in the userSchema to false. Is it possible to achieve? |
Beta Was this translation helpful? Give feedback.
Hi! The server will automatically detect when the client has left: either when the WebSocket connection is closed (right away), or when the heartbeat mechanism fails (may take up to 45 seconds by default).
So you shouldn't have to monitor for zombie connections.