How to implement graceful shutdown of server with automatic client reconnection #5030
Replies: 1 comment 8 replies
-
Hi @giovanni-bertoncelli , did you find an answer to your problem ? I am stuck in a similar situation. I have a socket connection between my server which is running in AWS ASG group with EC2 instances and frontend portal running separately. Now the problem is the socket connection disconnect when the any instance downscale and then reconnects to some other instance immediately due to socket reconnection mechanism. Now the problem is I have to update some fields of the user if the socket disconnection is initiated by the user in the frontend portal and basically I was listening to ' disconnect ' event in backend for that. But now when the instance downscale the same fields are updated, which I want to prevent. I went through the disconnect reasons in socket.io documentation and felt that instance downscaling may come under the disconnect reason as 'server shutting down' but when I tested it the reason came to be 'transport close' which is the same reason when the tab is closed in frontend and therefore I am not able to differentiate between the two cases. |
Beta Was this translation helpful? Give feedback.
-
Question
I was wondering if there is any way to implement a graceful shutdown of socket.io and at the same time guarantee the client the chance to retry automatically (without any client custom implementation) the reconnection.
My use case is:
reconnect: true
optionI'd like to know if there is any way to implement this, ideally also with the Connection Recovery feature.
What I've already tried
io.close()
method (or theio.local.disconnectSockets()
one), there is no way to specify whenever the clients that receive the disconnection event should retry to reconnect (even if the transport is closed)transport close
disconnect reason, that is actually fatal.Beta Was this translation helpful? Give feedback.
All reactions