Skip to content

Commit

Permalink
Resetting connection when webSocketDidReceiveError is called by mostl…
Browse files Browse the repository at this point in the history
…y all POSIX error (#414)

Co-authored-by: Alvaro De La Cruz <alvaro@flatiron.sowftware>
  • Loading branch information
alvaro-delacruz-bat and Alvaro De La Cruz committed Aug 9, 2023
1 parent 413e94e commit ee97b42
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Sources/Extensions/PusherConnection+WebsocketDelegate.swift
Expand Up @@ -229,5 +229,23 @@ extension PusherConnection: WebSocketConnectionDelegate {
context: """
Error: \(error.debugDescription)
""")

// Resetting connection if we receive another POSIXError
// than ENOTCONN (57 - Socket is not connected)
if case .posix(let code) = error, code != .ENOTCONN {
resetConnection()

guard !intentionalDisconnect else {
Logger.shared.debug(for: .intentionalDisconnection)
return
}

guard reconnectAttemptsMax == nil || reconnectAttempts < reconnectAttemptsMax! else {
Logger.shared.debug(for: .maxReconnectAttemptsLimitReached)
return
}

attemptReconnect()
}
}
}

0 comments on commit ee97b42

Please sign in to comment.