From ee97b4266d26d3fd372b7c1ee8a162644d97d0c6 Mon Sep 17 00:00:00 2001 From: alvaro-delacruz-bat <132507598+alvaro-delacruz-bat@users.noreply.github.com> Date: Wed, 9 Aug 2023 02:43:40 -0400 Subject: [PATCH] Resetting connection when webSocketDidReceiveError is called by mostly all POSIX error (#414) Co-authored-by: Alvaro De La Cruz --- .../PusherConnection+WebsocketDelegate.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/Extensions/PusherConnection+WebsocketDelegate.swift b/Sources/Extensions/PusherConnection+WebsocketDelegate.swift index 166b627b..8ed7beb8 100644 --- a/Sources/Extensions/PusherConnection+WebsocketDelegate.swift +++ b/Sources/Extensions/PusherConnection+WebsocketDelegate.swift @@ -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() + } } }