Skip to content

Handle Network backend reconnects - #38

Closed
rchatham wants to merge 2 commits into
feature/network-migration-multipeer-e2efrom
feature/network-migration-reconnect-e2e
Closed

Handle Network backend reconnects#38
rchatham wants to merge 2 commits into
feature/network-migration-multipeer-e2efrom
feature/network-migration-reconnect-e2e

Conversation

@rchatham

@rchatham rchatham commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a bounded Network backend reconnect E2E scenario and fixes the reconnect issues it exposed. Also stabilizes the existing multi-peer broadcast E2E test by retrying the broadcast after connections settle.

Changes

  • Add testNetworkBackendReconnectsAfterPeerRestarts.
  • Verify Alice observes Bob connect, disconnect after Bob stops, then reconnect when a replacement Bob starts with the same service type/security.
  • Treat remote receive completion/errors as connection cancellation so the coordinator emits disconnect cleanup for the remaining peer.
  • Keep the existing automatic refresh behavior MultipeerConnectivity-only; Network transports keep their listener/browser running after disconnect so they can discover and reconnect without trying to restart cancelled NWListener/NWBrowser instances.
  • Stabilize the three-peer broadcast E2E by sending a short retry burst after Alice has connected to both peers and allowing duplicate receives to avoid over-fulfillment failures.

Verification

  • swift test --filter NetworkPeerLoopbackTests/testNetworkBackendReconnectsAfterPeerRestarts — passed
  • swift test --filter NetworkPeerLoopbackTests — 6 tests passed
  • swift test — 108 tests passed
  • xcodebuild test -project PeerConnectivity.xcodeproj -scheme PeerConnectivity -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.3.1' -configuration Debug — 108 tests passed
  • GitHub Actions pull_request CI — Swift Package Tests and Xcode Project Tests passed
  • GitHub Actions push CI — Swift Package Tests and Xcode Project Tests passed
  • Correctness reviewer — no merge-blocking findings
  • Security reviewer — no merge-blocking security findings

Notes / limitations

  • This PR focuses on one peer-restart reconnect path. More aggressive churn/stress coverage should stay in separate slices to avoid broadening real Bonjour/Network.framework test flakiness.

Stack context

Stacked on PR #36 (feature/network-migration-multipeer-e2e). This is the reconnect E2E coverage and fix slice of the Network migration stack.

@rchatham
rchatham force-pushed the feature/network-migration-reconnect-e2e branch from 3de9321 to f0965d9 Compare August 7, 2026 17:43
@rchatham
rchatham force-pushed the feature/network-migration-reconnect-e2e branch from f0965d9 to e1a857c Compare August 7, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds end-to-end coverage for Network backend disconnect/reconnect behavior (peer restart) and adjusts Network transport/session handling to properly emit disconnect cleanup, while also stabilizing the existing multi-peer broadcast E2E test to reduce flakiness.

Changes:

  • Add a bounded Network backend reconnect E2E test (testNetworkBackendReconnectsAfterPeerRestarts).
  • Update Network receive handling to treat remote receive completion/errors as disconnect signals for cleanup.
  • Stabilize the existing multi-peer broadcast E2E test by retrying the broadcast and tolerating duplicate receives.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Sources/PeerConnectionManager.swift Limits automatic refresh-on-disconnect behavior to MultipeerConnectivity backend to support Network backend reconnect behavior.
Sources/NetworkPeerTransport.swift Adjusts Network receive loop behavior to emit disconnect/cancellation cleanup when the remote side completes/errors.
PeerConnectivityTests/NetworkPeerLoopbackTests.swift Adds reconnect E2E scenario and stabilizes multi-peer broadcast E2E via retry + duplicate-tolerant expectations.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Sources/NetworkPeerTransport.swift
@rchatham

Copy link
Copy Markdown
Owner Author

Superseded by consolidated PR #42. No commits were discarded; this branch is preserved as a recovery and reference point. Addressed review findings were replied to and resolved before consolidation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants