Add a timeout to network-info fetch to prevent blank web view and lost connection on launch#5017
Open
bgoncal wants to merge 4 commits into
Open
Add a timeout to network-info fetch to prevent blank web view and lost connection on launch#5017bgoncal wants to merge 4 commits into
bgoncal wants to merge 4 commits into
Conversation
URL resolution now awaits NEHotspotNetwork.fetchCurrent, whose completion occasionally never fires at launch/foreground (before location services are ready). With no timeout, the network-info refresh and every activeURL() awaiting it hang indefinitely, leaving a blank web view that never reloads, no WebSocket connection, and no user in the account row. Bound the fetch with a 3s timeout; on timeout keep the last-known network state instead of hanging or clearing it.
Contributor
|
Found 3 unused localization strings in the codebase. Click to see detailsTo remove them, run the |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a bounded timeout to the iOS network-info fetch so URL resolution can’t hang indefinitely during launch/foreground, preventing downstream stalls (blank WKWebView, no WS connect, missing user row) when NEHotspotNetwork.fetchCurrent never calls back.
Changes:
- Wraps
NEHotspotNetwork.fetchCurrentin a 3-second timeout withinConnectivityWrapper.performNetworkStateFetch(). - On timeout, preserves the cached/last-known
NetworkStateinstead of blocking or replacing it with empty data.
Address review feedback: move the fetch timeout into the shared fetchNetworkState() behind an injectable raw-fetch closure and a configurable timeout, and include the duration in the timeout log so it is actionable when tuning. Adds tests covering the timeout-preserves- last-known-state path and the normal completion path.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ConnectivitySensorTests leaves Current.connectivity.currentNetworkState overridden, so the new timeout tests relying on the default routing hit that stale closure. Call fetchNetworkState() directly instead. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Since URL resolution moved to
async(#4942 / #4953), every path that picks the active URL awaits a freshNEHotspotNetwork.fetchCurrent. That completion handler occasionally never fires (seen at launch/foreground, before location services are ready), and there was no timeout, sorefreshNetworkInformation()/activeURL()would hang indefinitely. Everything awaiting them then stalls at once:loadActiveURLIfNeededInProgressstucktrue, so no later event retries it — blank page that never reloadsTasknever reachesconnectAPI)currentUsernever completes)This matches the intermittent reports of a blank web view that won't reload, servers listed with no username, and no WebSocket connection.
Fix: bound
performNetworkStateFetch()with a 3s timeout. If the fetch doesn't return in time, keep the last-known network state instead of hanging (or overwriting it with an empty one). Callers always make progress, and the normal launch/foreground events re-drive the connection once network info is available. Catalyst reads network info synchronously and is unaffected.Screenshots
Not applicable — no user-facing/UI change.
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#
Any other notes
fetchCurrentnormally returns well under a second.