diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 0a754a9..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,95 +0,0 @@ -on: - push: - branches: [ main ] - -jobs: - check-release-tag: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - uses: actions/setup-node@v3 - - name: Prepare tag - id: prepare_tag - continue-on-error: true - run: | - npm install --location=global podspec-bump - export TAG=$(podspec-bump --dump-version -p NWWebSocket.podspec) - echo "TAG=$TAG" >> $GITHUB_ENV - export CHECK_TAG=$(git tag | grep $TAG) - if [[ $CHECK_TAG ]]; then - echo "Skipping because release tag already exists" - exit 1 - fi - - name: Output - id: release_output - if: ${{ steps.prepare_tag.outcome == 'success' }} - run: | - echo "::set-output name=tag::${{ env.TAG }}" - outputs: - tag: ${{ steps.release_output.outputs.tag }} - - build: - runs-on: macos-latest - needs: check-release-tag - if: ${{ needs.check-release-tag.outputs.tag }} - steps: - - uses: actions/checkout@v2 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v - outputs: - tag: ${{ needs.check-release-tag.outputs.tag }} - - publish-cocoapods: - runs-on: ubuntu-latest - needs: build - if: ${{ needs.build.outputs.tag }} - steps: - - uses: actions/checkout@v2 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.2.2' - - run: | - gem install cocoapods - - git config user.email "pusher-ci@pusher.com" - git config user.name "Pusher CI" - - git tag -a ${{ needs.build.outputs.tag }} -m "${{ needs.build.outputs.tag }}" - git push origin ${{ needs.build.outputs.tag }} - - pod trunk push NWWebSocket.podspec - env: - COCOAPODS_TRUNK_TOKEN: ${{ secrets.PUSHER_CI_COCOAPODS_TOKEN }} - outputs: - release_version: ${{ needs.build.outputs.tag }} - - create-github-release: - runs-on: ubuntu-latest - needs: publish-cocoapods - if: ${{ needs.publish-cocoapods.outputs.release_version }} - steps: - - uses: actions/checkout@v2 - - name: Prepare tag - run: | - export TAG=${{ needs.publish-cocoapods.outputs.release_version }} - echo "TAG=$TAG" >> $GITHUB_ENV - - name: Setup git - run: | - git config user.email "pusher-ci@pusher.com" - git config user.name "Pusher CI" - - name: Create Release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ env.TAG }} - release_name: ${{ env.TAG }} - draft: false - prerelease: false - - diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml deleted file mode 100644 index 7501428..0000000 --- a/.github/workflows/swift.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: CI - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: macos-latest - - steps: - - uses: actions/checkout@v2 - - name: Build - run: swift build -v - - name: Run tests - run: swift test -v diff --git a/Sources/NWWebSocket/Model/Client/NWWebSocket.swift b/Sources/NWWebSocket/Model/Client/NWWebSocket.swift index 2eb1643..6768e12 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) } @@ -548,19 +550,17 @@ open class NWWebSocket: WebSocketConnection { } } + /// Determine if a Network error represents an unexpected disconnection event. /// - Parameter error: The `NWError` to inspect. /// - Returns: `true` if the error represents an unexpected disconnection event. + /// - Note: Any POSIX error from the read loop indicates the connection is dead. + /// The previous selective list (ETIMEDOUT, ENOTCONN, ECANCELED, ENETDOWN, ECONNABORTED) + /// missed errors like ENODATA (96) which also indicate a dead connection. private func isDisconnectionNWError(_ error: NWError) -> Bool { - if case let .posix(code) = error, - code == .ETIMEDOUT - || code == .ENOTCONN - || code == .ECANCELED - || code == .ENETDOWN - || code == .ECONNABORTED { + if case .posix(_) = error { return true - } else { - return false } + return false } }