Skip to content

Use NWPathMonitor for Apple reachability#1431

Open
bmehta001 wants to merge 26 commits into
microsoft:mainfrom
bmehta001:bhamehta/apple-reachability-longterm
Open

Use NWPathMonitor for Apple reachability#1431
bmehta001 wants to merge 26 commits into
microsoft:mainfrom
bmehta001:bhamehta/apple-reachability-longterm

Conversation

@bmehta001
Copy link
Copy Markdown
Contributor

@bmehta001 bmehta001 commented Apr 29, 2026

Fixes #1370. Supersedes #1371.

Summary

This PR fixes the iOS 18 reachability crash by removing the internal ODWReachability helper and moving the SDK's Apple network detection directly to NWPathMonitor.

ODWReachability was internal-only, so we do not need to preserve its compatibility wrapper or vendored third-party snapshot. This keeps one Apple reachability implementation in the SDK and avoids the extra notifier/waiter/race surface from maintaining two backends.

What changed

  • NetworkInformationImpl.mm now owns Apple reachability directly through nw_path_monitor_create().
  • The vendored third_party/Reachability snapshot, its README, and its iOS unit tests were removed.
  • CMake and Xcode test project references to ODWReachability were removed.
  • build-ios.sh now defaults to iOS 12.0, matching the README support matrix.
  • The OSS component list and third_party/cgmanifest.json no longer list Tony Million Reachability.

Compatibility notes

  • The SDK support matrix already lists iOS 12+ and macOS 10.15+.
  • On runtimes older than iOS 12 / macOS 10.14, NetworkInformationImpl leaves network type/cost as Unknown instead of using SCNetworkReachability.
  • SDK production network detection remains generic network-path detection; it is not an endpoint-specific HTTPS probe.

Validation

  • The ODWReachability removal was checked for stale references across the repo.
  • third_party/cgmanifest.json was validated after removing the Reachability entry.
  • A focused code review found no material issues in the removal.

Replace the deprecated SCNetworkReachability APIs with NWPathMonitor
for modern Apple deployment targets (iOS 12+, macOS 10.14+). The legacy
SCNetworkReachability path is retained behind a compile-time check for
older targets.

Changes:
- NetworkInformationImpl.mm: refactor to use NWPathMonitor as the
  primary reachability mechanism, with SCNetworkReachability as fallback
  for older deployment targets only
- ODWReachability.h/m: add NWPathMonitor-based implementation gated on
  availability, keeping SCNetworkReachability for backward compatibility
- Remove dead private header imports from tests

This eliminates the -Wdeprecated-declarations build failures on
Xcode 26.4+ without needing pragma suppressions.

Fixes microsoft#1425

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bmehta001 bmehta001 requested a review from a team as a code owner April 29, 2026 22:01
bmehta001 and others added 2 commits April 29, 2026 15:32
PR microsoft#1431 should not carry changes in ODWReachabilityTests.mm.
Restore the socket header imports so the branch only contains the
reachability implementation changes.

Files changed:
- tests/unittests/obj-c/ODWReachabilityTests.mm

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep PR microsoft#1431 focused on the reachability implementation changes by
reverting the top-of-file/header-area edits in ODWReachability.m.

Files changed:
- third_party/Reachability/ODWReachability.m

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 updates the Apple-side reachability/network detection code paths to avoid SCNetworkReachability deprecation build failures by preferring modern APIs on newer deployment targets while retaining a legacy fallback for older targets.

Changes:

  • Adds a compile-time deployment-target gate (ODW_LEGACY_REACHABILITY_REQUIRED) to exclude legacy SCNetworkReachability code from modern builds.
  • Refactors NetworkInformationImpl.mm to split modern (NWPathMonitor) vs legacy (ODWReachability notification) setup paths and compile out legacy members when not needed.
  • Wraps multiple ODWReachability.m code paths with #if ODW_LEGACY_REACHABILITY_REQUIRED to avoid compiling deprecated SCNetworkReachability usage for modern targets.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
third_party/Reachability/ODWReachability.h Introduces ODW_LEGACY_REACHABILITY_REQUIRED macro to compile out legacy reachability code on modern deployment targets.
third_party/Reachability/ODWReachability.m Adds compile-time gating around legacy SCNetworkReachability branches to avoid deprecation warnings/errors on modern targets.
lib/pal/posix/NetworkInformationImpl.mm Refactors network detection setup into modern (NWPathMonitor) vs legacy (ODWReachability) implementations and gates legacy members/functions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
bmehta001 and others added 2 commits May 1, 2026 19:20
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make the modern ODWReachability WWAN path explicit so iOS 12+
builds unambiguously use the NWPathMonitor-backed state, while the
legacy SCNetworkReachability fallback remains only for older Apple
deployment targets.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bmehta001 bmehta001 changed the title Migrate Apple reachability from SCNetworkReachability to NWPathMonitor Use NWPathMonitor for modern Apple reachability with legacy fallback May 2, 2026
@bmehta001 bmehta001 requested a review from Copilot May 2, 2026 16:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Modern reachability should not synchronously resolve DNS or reject the generic internet reachability address, and the path monitor context must not hold a stale raw owner pointer. Also avoid blocking the main thread while waiting for the first NWPathMonitor snapshot.

Files changed:
- third_party/Reachability/ODWReachability.m

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
@bmehta001 bmehta001 self-assigned this May 3, 2026
bmehta001 and others added 3 commits May 5, 2026 11:11
Annotate the modern-path helpers (`ODWModernPathIsReachable`,
`ensureModernPathMonitor`, `awaitModernPathSnapshot`,
`handleModernPathUpdate:`, `notifyModernPathChange`) with
`API_AVAILABLE(macos(10.14), ios(12.0))` so that compiling against an
older deployment target no longer triggers
`-Wunguarded-availability-new` errors under `-Werror`.

Also fix a latent bug in `isReachableViaWWAN` where the modern-path
snapshot was computed before the `if (@available(...))` guard. On
macOS 10.10 / iOS 10.0 deployment targets running on a host that
lacks NWPathMonitor, this would invoke unavailable Network framework
APIs. The modern-path branch is now only taken inside the
`@available` block on legacy builds, mirroring the structure used in
`isReachableViaWiFi`.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
`-handleModernPathUpdate:` and `-awaitModernPathSnapshot` previously
read `self.initialPathSemaphore` more than once across the nil-check
and the matching `dispatch_semaphore_signal`/`dispatch_semaphore_wait`
call. `-stopNotifier` clears the property from an arbitrary thread, so
the second read could observe nil and pass it into libdispatch (which
crashes on a nil semaphore).

Capture the semaphore into a strong local once. Under ARC the local
retains the dispatch_semaphore_t for the duration of the call, so a
concurrent stop will no longer race the signal/wait.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@bmehta001 bmehta001 requested a review from Copilot May 11, 2026 17:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.h Outdated
bmehta001 and others added 2 commits May 11, 2026 13:03
Preserve host/address-specific reachability semantics with SCNetworkReachability while keeping Network.framework for general path monitoring.

Avoid waiting for the first NWPathMonitor update on the monitor queue, and use platform-specific Apple availability gates.

Files changed:

- third_party/Reachability/ODWReachability.h

- third_party/Reachability/ODWReachability.m

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Leave the Network.framework status initialization in modern monitor setup so older Apple deployment-target builds do not touch an availability-gated symbol from init.

Files changed:

- third_party/Reachability/ODWReachability.m

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove tvOS and watchOS deployment-target handling because the SDK does not support those targets; keep the availability gates focused on iOS and macOS.

Files changed:

- third_party/Reachability/ODWReachability.h

- third_party/Reachability/ODWReachability.m

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread lib/pal/posix/NetworkInformationImpl.mm Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Serialize NWPathMonitor initialization and use a dispatch group so every caller waiting for the first path snapshot is released when the snapshot arrives or monitoring stops.

Files changed:

- third_party/Reachability/ODWReachability.m

- lib/pal/posix/NetworkInformationImpl.mm

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Copilot: host:port inputs were parsed as a scheme with no host. Parse by prepending https:// before NSURLComponents when no explicit scheme separator is present.

Copilot: invalid.hostname is syntactically valid under SCNetworkReachabilityCreateWithName. Update tests to distinguish malformed host URLs from unresolved hostnames.

Files changed:

- third_party/Reachability/ODWReachability.m

- tests/unittests/obj-c/ODWReachabilityTests.mm

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread tests/unittests/obj-c/ODWReachabilityTests.mm Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Copilot: ODWReachability.m could look non-ARC under CMake because ARC was only set in CXX flags. Compile the vendored Objective-C source with -fobjc-arc explicitly.

Copilot: rename the unresolved-hostname test to describe constructor acceptance rather than DNS reachability.

Files changed:

- lib/CMakeLists.txt

- tests/unittests/obj-c/ODWReachabilityTests.mm

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread third_party/Reachability/ODWReachability.m Outdated
Comment thread third_party/Reachability/ODWReachability.m Outdated
Copilot: delete the dead URLSession response helper left behind after removing endpoint probes.

Copilot: make modern startNotifier match legacy behavior by wiring callbacks and returning without waiting for the first NWPathMonitor snapshot.

Copilot: add a start/stop notifier test that verifies startup returns promptly.

Files changed:

- third_party/Reachability/ODWReachability.m

- tests/unittests/obj-c/ODWReachabilityTests.mm

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

bmehta001 and others added 2 commits May 25, 2026 18:16
Restore the access-specifier indentation in NetworkInformationImpl.mm to the 4-space convention used on main.

Restore the trailing blank line at the end of lib/CMakeLists.txt accidentally dropped during the ARC compile-flags patch.

Realign one stray line in ODWReachability.m reachabilityFlags() to match surrounding column alignment.

Files changed:

- lib/CMakeLists.txt

- lib/pal/posix/NetworkInformationImpl.mm

- third_party/Reachability/ODWReachability.m

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Align build-ios.sh with the README support matrix (iOS 12+) so default builds compile out the legacy SCNetworkReachability code path that ODW_LEGACY_REACHABILITY_REQUIRED gates. Borrowed from microsoft#1371.

Files changed:

- build-ios.sh

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
ODWReachability is internal-only, so keep the SDK on direct NWPathMonitor instead of maintaining a compatibility wrapper around the vendored Reachability snapshot.

Remove the vendored Reachability sources, tests, CMake wiring, Xcode references, and OSS manifest entries. Unsupported pre-iOS-12 / pre-macOS-10.14 runtimes now leave network state as Unknown instead of using SCNetworkReachability.

Files changed:

- lib/pal/posix/NetworkInformationImpl.mm

- lib/CMakeLists.txt

- tests/unittests/unittests-ios.xcodeproj/project.pbxproj

- tests/unittests/obj-c/ODWReachabilityTests.mm

- third_party/Reachability/*

- docs/List-of-OSS-Components.md

- third_party/cgmanifest.json

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bmehta001 bmehta001 changed the title Use NWPathMonitor for modern Apple reachability with legacy fallback Use NWPathMonitor for Apple reachability May 26, 2026
@bmehta001 bmehta001 requested a review from Copilot May 26, 2026 21:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

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.

Crash on iOS [ODWLogManager flushAndTeardown]

4 participants