+ 1
Socket.io disconnect randomly after some time.
Socket.io client is disconnecting and reconnecting randomly after some time. I have posted question on Stack overflow as well, please refer to it for more details. https://stackoverflow.com/questions/70450677/react-js-socket-io-disconnection-issue
6 Answers
+ 3
Yep, I've had same issue actually. But I managed to solve it differently. There was no issue on code side, it was sever configuration issue where it was hosted.
+ 3
Hi CalviŐ˛ marilynn
For me the issue was error handling on server. We had some issue on database and when socket was fired we got error. After getting error server was crashed and sockets gets disconnected.
We setup pm2 on server and configured it to auto restart if any error occurs.
From the frontend side we kept pinging server on ever 5 second to maintain connection. And inside socket.on("disconnect") event I immediately reconnected it.
I hope this will help you both.
+ 2
Raj Chhatrala though this may or may not be directly relevant to your question but it sounds like it might be .. https://stackoverflow.com/questions/40991599/socket-io-automatically-disconnects-socket?noredirect=1&lq=1
+ 1
Dear @Raj Chhatrala
Thank you for your response;
I am using Express JS as socket IO server
Do you mean I have to install pm2 package ? and make some configuration?
Do you have any piece of code that can helps me do it?
As I want to ask ; maybe the disconnect event is made by the user not because of other issues , how did you handle this case with emitting the message inside the disconnect
Thank you in advance
0
Raj Chhatrala I am facing the same issue with my react app as you encountered last time.
Do you mind sharing how you resolved the socket.io disconnection intermittent issue?
0
Hello
@RajChhatrala can you please mention what is the server configuration that has to be done ? because I am facing this problem
Thank you in advance