Replies: 1 comment 2 replies
-
Hi! A possible explanation is that your server was killed and restarted, so the cleanup method wasn't executed. Could it be possible? Else, I don't know how that can happen. Would you be able to get the state of the Socket, and the underlying connection ( I was not able to reproduce the issue with the load testing script here: https://socket.io/docs/v4/load-testing/#manual-client-creation const { Server } = require("socket.io");
const io = new Server(3000);
let connectionCount = 0, disconnectionCount = 0;
io.on("connection", socket => {
connectionCount++;
socket.on("disconnect", (reason) => {
disconnectionCount++;
});
});
setInterval(() => {
console.log(`current connected: ${io.sockets.sockets.size} ; total connections: ${connectionCount} ; total disconnections: ${disconnectionCount}`);
}, 5000); |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I searched socket.io issues found this one about client-side disconnect is not detected. It was closed in 2017 but others commented they still hit the problem and this is what I have been experiencing (socket.io 2.3).
Our work flow are like these:
io.on('connection', socket => { /* ... */ });
I will record the userid with socket.id in redis (using a hash with socket.id as the field and user.id as the value) and insocket.on('disconnect', /* ... */);
I will delete that pair of user.id and socket.io.Here redis recorded user
134_243_1000962235
has 2 socket connectionsTfJmlyJngwG5c6aVAABT
&gAACwSLokQnzAVb0AADV
. We implement our system that if we detect a user does login with another ws connection while we still have the old ws connection record we will callclose()
on socket.io.clientSo I think that the reason I have several socket.ids point to one user is that I didn't get the disconnect event for those socket.id so they still exist in our redis record. I assume that if the network connection is bad, it is possbile that I won't get the disconnect event at the server side. But the problem is that it happens regularly and I can't figure out a way to clear those obsolete records.
Has anyone also experienced this problem ? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions