Reconnect fails repeatedly for some users
Describe the bug
Some of our users disconnect from the server repeatedly when we try to reconnect with this close reason: CloseReason: code [1002], reason [The client frame set the reserved bits to [4] for a message with opCode [7] which was not supported by this endpoint].
Expected behavior
Not getting opCode 7 on the server since it is reserved.
Environment:
- OS/Version: [e.g. iOS/13.3] iOS (not sure about the version as it happens in prod for random users)
- Starscream Version [e.g. 4.0.4] 4.0.4
- Xcode version [e.g. 11.5] Couldn't repro locally
Additional context
Based on logs it appears that users manage to connect to the server with no issues at first. However, after they disconnect we try to reconnect which results in the mentioned issue as if the socket ends up in a bad state which makes the reconnect attempt unsuccessful. When it goes to this state the client keeps trying to connect to the server and fails again and again with the same error. After 30 seconds or so in most cases the logs stop (not sure if the client app crashes or the user leaves or ....)
Here is the code we use on the client to reconnect. It keeps trying socket.connect until it connects:
func didReceive(event: WebSocketEvent, client: WebSocket) {
switch event {
case .connected(_):
isConnected = true
reconnectTimer?.invalidate()
...
case .disconnected, .cancelled, .reconnectSuggested, .error:
isConnected = false
reconnectTimer?.invalidate()
reconnectTimer = Timer.scheduledTimer(timeInterval: TimeInterval(3), target: self, selector: #selector(reconnect), userInfo: nil, repeats: true)
}
}
@objc private func reconnect() {
socket.connect()
}
Please advice if we need to change the reconnect logic on our end.
hi, did u found any solution?