Skip to content

Commit 8b857d7

Browse files
committed
fix
1 parent 501c6bd commit 8b857d7

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Sources/NWWebSocket/Model/Client/NWWebSocket.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ open class NWWebSocket: WebSocketConnection {
526526
// Only schedule disconnection if we haven't already scheduled one
527527
if isDisconnectionNWError(error) && disconnectionWorkItem == nil {
528528
let reasonData = "The websocket disconnected unexpectedly".data(using: .utf8)
529+
// Cancel the zombie connection to ensure reconnect creates a fresh NWConnection
530+
connection?.cancel()
529531
scheduleDisconnectionReporting(closeCode: .protocolCode(.goingAway),
530532
reason: reasonData)
531533
}
@@ -548,19 +550,17 @@ open class NWWebSocket: WebSocketConnection {
548550
}
549551
}
550552

553+
551554
/// Determine if a Network error represents an unexpected disconnection event.
552555
/// - Parameter error: The `NWError` to inspect.
553556
/// - Returns: `true` if the error represents an unexpected disconnection event.
557+
/// - Note: Any POSIX error from the read loop indicates the connection is dead.
558+
/// The previous selective list (ETIMEDOUT, ENOTCONN, ECANCELED, ENETDOWN, ECONNABORTED)
559+
/// missed errors like ENODATA (96) which also indicate a dead connection.
554560
private func isDisconnectionNWError(_ error: NWError) -> Bool {
555-
if case let .posix(code) = error,
556-
code == .ETIMEDOUT
557-
|| code == .ENOTCONN
558-
|| code == .ECANCELED
559-
|| code == .ENETDOWN
560-
|| code == .ECONNABORTED {
561+
if case .posix(_) = error {
561562
return true
562-
} else {
563-
return false
564563
}
564+
return false
565565
}
566566
}

0 commit comments

Comments
 (0)