Skip to content

Harden Network backend connection lifecycle - #33

Closed
rchatham wants to merge 2 commits into
feature/network-migration-secure-transportfrom
feature/network-migration-connection-hardening
Closed

Harden Network backend connection lifecycle#33
rchatham wants to merge 2 commits into
feature/network-migration-secure-transportfrom
feature/network-migration-connection-hardening

Conversation

@rchatham

@rchatham rchatham commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the next Network backend hardening slice: bounded pending/connected connection lifecycle, handshake timeout cleanup, and transport state cleanup hooks.

Changes

  • Add internal NetworkPeerConnectionPolicy with defaults:
    • handshakeTimeout = 10s
    • maxPendingConnections = 16
    • maxConnectedPeers = 8
  • Cancel pending connections that do not complete the PeerConnectivity handshake before timeout.
  • Enforce pending connection and connected peer caps before accepting more Network connections.
  • Re-check connected peer capacity when handshakes arrive, so concurrently pending connections cannot overfill the registry.
  • Cancel and cleanup pending timeout work items when connections register, fail validation, are removed, or all connections are stopped.
  • Add NetworkPeerConnection.setStateHandler and wire Network .failed / .cancelled states back into coordinator cleanup.
  • Add focused coordinator coverage for:
    • handshake timeout cancellation
    • pending connection cap
    • connected peer cap before new pending connection
    • connected peer cap when pending handshakes complete concurrently

Verification

  • swift test --filter NetworkPeerCoordinatorTests — passed
  • swift test --filter NetworkPeerLoopbackTests — passed
  • swift test — 102 tests passed
  • xcodebuild test -project PeerConnectivity.xcodeproj -scheme PeerConnectivity -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.3.1' -configuration Debug — 102 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

  • Policy is internal for now to keep this PR focused and avoid public API churn before the Network backend is promoted.
  • Backoff/retry tuning and public configurability are deferred until we know the desired production defaults.
  • .networkFramework remains opt-in and still lacks streams/resource/UI parity.

Stack context

Stacked on PR #32 (feature/network-migration-secure-transport). This is the connection lifecycle hardening slice of the Network migration stack.

@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.

1 participant