I am using a server behind a NGINX load balancer. My server had an unexpected shutdown and restart. It takes a little time for the server to complete the boot process and during that time NGINX would return an error to anyone who tries to connect to the server.
It seems that if the server fails to reconnect once then it will not try again:
Setup to reproduce:
SocketManager connects initially then upgrades the connection to a websocket
The server on the other side shuts down causing the socket to close and the client code
It takes the server ~30 seconds to come back and be available
Logs:
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketManager: Starting reconnect
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketIOClient{/}: Handling event: statusChange with data: [connecting]
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketIOClient{/}: Handling event: reconnect with data: ["Socket Disconnected"]
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketManager: Trying to reconnect
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketIOClient{/}: Handling event: reconnectAttempt with data: [-1]
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketEngine: Starting engine. Server: wss://dev1.wisdo.com
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketEngine: Handshaking
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketEnginePolling: Doing polling GET https://dev1.wisdo.com/socket.io/?transport=polling&b64=1
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketEnginePolling: Got polling response
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketEnginePolling: Got poll message:
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.8.1</center>
</body>
</html>
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketEngine: Got message:
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.8.1</center>
</body>
</html>
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: ERROR SocketManager: Got unknown error from server
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.8.1</center>
</body>
</html>
Dec 17 10:26:21 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketIOClient{/}: Handling event: error with data: ["Got unknown error from server ...\r\n"]
Dec 17 10:26:31 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketManager: Trying to reconnect
Dec 17 10:26:31 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketIOClient{/}: Handling event: reconnectAttempt with data: [-2]
Dec 17 10:26:31 Gils-MacBook-Pro-4 wisdo[96407]: LOG SocketManager: Tried connecting an already active socket
.... The client now loops but does not try to access the server again..
It will just call connect again and again and again but because status is reconnecting it will just print the warning and do nothing
Hey.. did you find any solution to this?
@odedsh @nuclearace
Also seeing this issue - version 13.1.1
@kinza88 @headlessme
In our code we listen to 'reconnectAttempt' event and based on the number of failed attempts we
[_manager disconnect];
[_manager didDisconnectWithReason:@"Reconnect Failed"];
@nuclearace thoughts on getting the above fix merged?
@headlessme I will need to look at the fix and test things out.
I'm seeing the same thing, posted my log in here #1016 just gets stuck in a reconnect loop from then on, this is not the behaviour in v12, that works fine. With v13 if I issue a disconnect on the socket within the reconnect attempt event handler it will connect on the next reconnect attempt. So this is inline with the above fix, it seems like the flag is not reset and therefore it will not try and connect.
Disconnecting manager first works for me.
My code is as follow
socket?.onAny { (data) in
if data.event == "reconnectAttempt" {
self.socketManager?.disconnect()
self.connectSocket()
}
}
Most helpful comment
Hey.. did you find any solution to this?
@odedsh @nuclearace