From 3d3b8a24b17a0f079195031ca86af117fc158bef Mon Sep 17 00:00:00 2001 From: 40handz Date: Tue, 3 Mar 2026 10:24:11 -0500 Subject: [PATCH] Fix ENODATA and unrecognised POSIX errors not treated as disconnections --- CHANGELOG.md | 8 +++++++- NWWebSocket.podspec | 2 +- README.md | 4 ++-- Sources/NWWebSocket/Model/Client/NWWebSocket.swift | 5 +++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c6f5c..c7e0e8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). -## [Unreleased](https://github.com/pusher/NWWebSocket/compare/0.5.9...HEAD) +## [Unreleased](https://github.com/pusher/NWWebSocket/compare/0.5.10...HEAD) + +## [0.5.10](https://github.com/pusher/NWWebSocket/compare/0.5.9...0.5.10) - 2026-03-03 + +### Fixed + +- Treat any POSIX error as a disconnection to handle ENODATA (96) and other unrecognised codes that leave the connection in a zombie state ## [0.5.9](https://github.com/pusher/NWWebSocket/compare/0.5.8...0.5.9) - 2025-12-05 diff --git a/NWWebSocket.podspec b/NWWebSocket.podspec index 506f5c1..5cb387a 100644 --- a/NWWebSocket.podspec +++ b/NWWebSocket.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'NWWebSocket' - s.version = '0.5.9' + s.version = '0.5.10' s.summary = 'A WebSocket client written in Swift, using the Network framework from Apple' s.homepage = 'https://github.com/pusher/NWWebSocket' s.license = 'MIT' diff --git a/README.md b/README.md index caa01ea..c5c788d 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios, '14.0' use_frameworks! -pod 'NWWebSocket', '~> 0.5.9' +pod 'NWWebSocket', '~> 0.5.10' ``` Then, run the following command: @@ -90,7 +90,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/pusher/NWWebSocket.git", - .upToNextMajor(from: "0.5.9")), + .upToNextMajor(from: "0.5.10")), ], targets: [ .target( diff --git a/Sources/NWWebSocket/Model/Client/NWWebSocket.swift b/Sources/NWWebSocket/Model/Client/NWWebSocket.swift index 2eb1643..d6b6879 100644 --- a/Sources/NWWebSocket/Model/Client/NWWebSocket.swift +++ b/Sources/NWWebSocket/Model/Client/NWWebSocket.swift @@ -526,6 +526,8 @@ open class NWWebSocket: WebSocketConnection { // Only schedule disconnection if we haven't already scheduled one if isDisconnectionNWError(error) && disconnectionWorkItem == nil { let reasonData = "The websocket disconnected unexpectedly".data(using: .utf8) + // Cancel the zombie connection to ensure reconnect creates a fresh NWConnection + connection?.cancel() scheduleDisconnectionReporting(closeCode: .protocolCode(.goingAway), reason: reasonData) } @@ -559,6 +561,9 @@ open class NWWebSocket: WebSocketConnection { || code == .ENETDOWN || code == .ECONNABORTED { return true + } else if case .posix(_) = error { + // Catch-all for other POSIX errors (e.g. ENODATA) that also indicate a dead connection + return true } else { return false }