Improve reliability of online/offline detection when fetching dependencies #9378
+12
−42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When fetching dependencies on Darwin we relied on SCNetworkReachability to determine if the user is offline when a dependency fetch fails. This check considered
SCNetworkReachabilityFlags.transientConnectionto be considered "offline", however this state still has connectivity.If the user had the dependency cached, this would result in the cached local dependency being used instead of a fetch of the latest dependency. Ultimately this meant very occasionally the user may end up with a stale dependency when they had all the requirements met to ge the latest one.
Move off of the SCNetworkReachability APIs as they're not really recommended for determining online status, and simply check if the fetch failed with a "Could not resolve host" error. This is what we actually want to check for anyway. Even if the host is down but the connection is fine the host being down is what is relevant to whether or not we should try and use the cached dependency.