centrifugal / centrifuge-swift

Swift client SDK for bidirectional real-time communication with Centrifugo and Centrifuge-based server over WebSocket
MIT License
47 stars 41 forks source link

Connected successfully after 5 to 8 mins later disconnect issue occurs and not able to auto reconnect . #78

Closed isandeepj closed 1 year ago

isandeepj commented 1 year ago

We get onError method error type CentrifugeError.transportError The operation couldn’t be completed. (SwiftCentrifuge.WSError error 1.) but our app is live but not able to reproduce issue on debug mode which reason to this disconnect issue occurs not able to reconnect. so we are facing issue. did not get proper error reason so it very difficulte how to fix it this issue.

If we log using this event.error.localizedDescription then we get The operation couldn’t be completed. (SwiftCentrifuge.CentrifugeError error 0.)


        if let centrifugeError = event.error as? CentrifugeError {
            switch centrifugeError {
            case .timeout:
                errMsg = "timeout"
            case .duplicateSub:
                errMsg = "duplicateSub"
                return
            case .clientDisconnected:
                errMsg = "clientDisconnected"
                return
            case .subscriptionUnsubscribed:
                errMsg = "subscriptionUnsubscribed"
                return
            case .transportError(let err):
                errMsg = "transportError: \(err.localizedDescription)"
            case .tokenError(let err):
                errMsg = "tokenError: \(err.localizedDescription)"
            case .connectError(let err):
                errMsg = "connectError: \(err.localizedDescription)"
            case .refreshError(let err):
                errMsg = "refreshError: \(err.localizedDescription)"
            case .subscriptionSubscribeError(let err):
                errMsg = "subscriptionSubscribeError: \(err.localizedDescription)"
            case .subscriptionTokenError(let err):
                errMsg = "subscriptionTokenError: \(err.localizedDescription)"
            case .subscriptionRefreshError(let err):
                errMsg = "subscriptionRefreshError: \(err.localizedDescription)"
            case .replyError(let code, let message, _):
                errMsg = "replyError: code: \(code) message:\(message)"
            }
        }
        if errMsg.notEmpty {
            errMsg += "; localizedDescription: \(event.error.localizedDescription)"
        } else {
            errMsg = event.error.localizedDescription
        }```

 Error message got while log on amplitude.        
 `"transportError: The operation couldn’t be completed. (SwiftCentrifuge.WSError error 1.); localizedDescription: The operation couldn’t be completed. (SwiftCentrifuge.CentrifugeError error 0.)"` 
FZambia commented 1 year ago

Hello @sandeep-yudiz

For now I don't have any idea where it can come from, we don't have this message inside centrifuge-swift source code. Could you provide more details:

  1. Version of centrifuge-swift? Version of server?
  2. Does this happen rarely on some devices? Or every time? Any special details you may provide?
  3. which reason to this disconnect issue occurs not able to reconnect - this is not very clear to me, could you elaborate more – after getting the error websocket disconnects? are you getting disconnect callback? if yes, does centrifuge-swift reconnects after disconnecting?
isandeepj commented 1 year ago

Hello @FZambia

  1. Version of centrifuge-swift => SwiftCentrifuge (0.5.5), Server version 3.2.0

  2. Does this happen rarely on some devices? Or every time? Any special details you may provide? => Does this happen on some users devices. Maybe this data will help you! Screenshot 2023-01-20 at 12 53 58 PM

We tracking error on the methods with try to extract data from error.

func onError(_ client: CentrifugeClient, _ event: CentrifugeErrorEvent) {
        var errMsg = ""
        if let centrifugeError = event.error as? CentrifugeError {
            switch centrifugeError {
            case .timeout:
                errMsg = "timeout"
            case .duplicateSub:
                errMsg = "duplicateSub"
                return
            case .clientDisconnected:
                errMsg = "clientDisconnected"
                return
            case .subscriptionUnsubscribed:
                errMsg = "subscriptionUnsubscribed"
                return
            case .transportError(let err):
                errMsg = "transportError: \(err.localizedDescription)"
            case .tokenError(let err):
                errMsg = "tokenError: \(err.localizedDescription)"
            case .connectError(let err):
                errMsg = "connectError: \(err.localizedDescription)"
            case .refreshError(let err):
                errMsg = "refreshError: \(err.localizedDescription)"
            case .subscriptionSubscribeError(let err):
                errMsg = "subscriptionSubscribeError: \(err.localizedDescription)"
            case .subscriptionTokenError(let err):
                errMsg = "subscriptionTokenError: \(err.localizedDescription)"
            case .subscriptionRefreshError(let err):
                errMsg = "subscriptionRefreshError: \(err.localizedDescription)"
            case .replyError(let code, let message, _):
                errMsg = "replyError: code: \(code) message:\(message)"
            }
        }
        if errMsg.notEmpty {
            errMsg += "; localizedDescription: \(event.error.localizedDescription)"
        } else {
            errMsg = event.error.localizedDescription
        }
        TrackingManager.sendEvent("error_centrifuge", eventProperties: ["error": errMsg])
  }
  1. which reason to this disconnect issue occurs not able to reconnect - this is not very clear to me, could you elaborate more – after getting the error websocket disconnects? are you getting disconnect callback? if yes, does centrifuge-swift reconnects after disconnecting? => When user received above error they are disconnected but not able to reconnect on `SwiftCentrifuge.CentrifugeError error 0. User need to kill the app and reopen the app.
FZambia commented 1 year ago

Version of centrifuge-swift => SwiftCentrifuge (0.5.5), Server version 3.2.0

Starting from v0.5.0 this SDK does not support Centrifugo < v4. See release notes https://github.com/centrifugal/centrifuge-swift/releases/tag/0.5.0, and also this is stated in the README. There were many changes in protocol.

I am not sure that the error will disappear upon using proper versions – it may be normal actually as network errors happen. But probably SDK will reconnect properly.