Reconnection doesn't work
I use Socket IO v13.1.1 on iOS app with server (apache nginx, Socket IO v2.0.4). We test what will happen if server reboots.
- iOS app is connected to the server
- Then the server is rebooted
- iOS app tries to reconnect
iOS library constantly emits reconnectAttempt event (default config). Why it doesn't reconnects?
Is iOS app supposed to perform some custom actions?
I was able to fix my problem by disabling built-in reconnection:
manager = SocketManager(socketURL: serverURL, config: [.reconnects(false)])
And then I created a Timer that will periodically check if the socket is connected and reconnects if necessary.
I have the same problem
Sorry for missing this. Does the logs spit out something about an unknown session id?
I have the same issue.
If I listen to the 'reconnectAttempt' event, which is still fired as expected, and in that I call disconnect on the SocketManager, the reconnect attempt will work. This doesn't seem to fire the 'disconnect' event.
It may be worth noting that the socket in question is on a non-root namespace
2018-06-18 18:29:05.424781+0100 four[2661:2628085] LOG SocketManager: Starting reconnect
2018-06-18 18:29:05.425002+0100 four[2661:2628085] LOG SocketIOClient{/ipad}: Handling event: statusChange with data: [connecting]
2018-06-18 18:29:05.425093+0100 four[2661:2628085] LOG SocketIOClient{/ipad}: Handling event: reconnect with data: ["Socket Disconnected"]
Reconnect
2018-06-18 18:29:05.425401+0100 four[2661:2628085] LOG SocketManager: Trying to reconnect
2018-06-18 18:29:05.425491+0100 four[2661:2628085] LOG SocketIOClient{/ipad}: Handling event: reconnectAttempt with data: [-1]
Reconnect Attempt
2018-06-18 18:29:05.437001+0100 four[2661:2628085] LOG SocketManager: Adding engine
2018-06-18 18:29:05.437254+0100 four[2661:2628112] LOG SocketEngine: Engine is being released
2018-06-18 18:29:05.437425+0100 four[2661:2628251] LOG SocketEngine: Starting engine. Server: https://xxxx
2018-06-18 18:29:05.437449+0100 four[2661:2628251] LOG SocketEngine: Handshaking
2018-06-18 18:29:05.437613+0100 four[2661:2628251] LOG SocketEnginePolling: Doing polling GET https://xxxx/socket.io/?transport=polling&b64=1
2018-06-18 18:29:05.438333+0100 four[2661:2628123] TIC Read Status [1:0x0]: 1:57
2018-06-18 18:29:05.438352+0100 four[2661:2628123] TIC Read Status [1:0x0]: 1:57
2018-06-18 18:29:05.561286+0100 four[2661:2628112] LOG SocketEnginePolling: Got polling response
2018-06-18 18:29:05.561445+0100 four[2661:2628112] LOG SocketEnginePolling: Got poll message: <html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>
2018-06-18 18:29:05.561648+0100 four[2661:2628112] LOG SocketEngine: Got message: <html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>
2018-06-18 18:29:05.562229+0100 four[2661:2628085] ERROR SocketManager: Got unknown error from server <html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx</center>
</body>
</html>
2018-06-18 18:29:05.562381+0100 four[2661:2628085] LOG SocketIOClient{/ipad}: Handling event: error with data: ["Got unknown error from server <html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>502 Bad Gateway</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"]
2018-06-18 18:29:08.630287+0100 four[2661:2628085] LOG SocketManager: Trying to reconnect
2018-06-18 18:29:08.630664+0100 four[2661:2628085] LOG SocketIOClient{/ipad}: Handling event: reconnectAttempt with data: [-2]
Reconnect Attempt
2018-06-18 18:29:08.631158+0100 four[2661:2628085] LOG SocketManager: Tried connecting an already active socket
2018-06-18 18:29:11.930020+0100 four[2661:2628085] LOG SocketManager: Trying to reconnect
2018-06-18 18:29:11.930204+0100 four[2661:2628085] LOG SocketIOClient{/ipad}: Handling event: reconnectAttempt with data: [-3]
Reconnect Attempt
The socket manager is a property of a singleton class that is never disposed of
Disconnecting manager first works for me. My code is as follow
socket?.onAny { (data) in
if data.event == "reconnectAttempt" {
self.socketManager?.disconnect()
self.connectSocket()
}
}
Yeah I got it to work doing the same thing, #909 has a proposed fix that seems to make sense
I can confirm the same thing. After adding [self.manager disconnect]; before every [self.socket disconnect]; in my code, things are working as expected again.
I don't believe this should be closed. We are seeing the same behavior on v16.0.1
I don't believe this should be closed. We are seeing the same behavior on v16.0.1
Can you reopen this issue by yourself or my action is needed?
@willtrking I can conform this behavior on v16.0.1 too.
Disconnecting manager first works for me. My code is as follow
socket?.onAny { (data) in if data.event == "reconnectAttempt" { self.socketManager?.disconnect() self.connectSocket() } }
Solved with this solution, thank you very much.