fix(darwin): stop getLocation hanging on sparse location updates - #1052
Merged
Conversation
getLocation() could never complete when Core Location delivered fewer than three updates. The stale-location guard swallowed the first two updates by count to skip the cached "last known" fix, so a one-shot getLocation() only resolved on the third update. When few updates arrive — a static iOS-simulator "Custom Location" (#657, #955, #1005, #1013), reduced accuracy which emits a single update (#984), or a sparse first fix (#798) — the Dart Future hung forever with no error. Skip stale fixes by age instead of by count: deliver the first update whose timestamp is recent, which resolves getLocation() immediately while still ignoring the instantly-delivered cached location. Verified on an iOS simulator with a static Custom Location — an integration test that hangs (20s timeout) on the old code passes on the new code. Fixes #798, fixes #955, fixes #1005, fixes #657, fixes #1013
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.
The second root cause behind the iOS "getLocation never completes" cluster
The main-thread PR (#1050) fixed the
locationServicesEnabledhang. This fixes a separate root cause with the same symptom.didUpdateLocationsskipped the cached "last known" fix by counting:waitNextLocation = 2dropped the first two updates, so a one-shotgetLocation()only resolved on the third. When Core Location delivers fewer than three updates, the Dart Future hangs forever with no error:Fix
Skip stale fixes by age instead of by count — deliver the first update whose timestamp is recent. This resolves
getLocation()on the first fresh fix (never hangs) while still ignoring the instantly-delivered cached location, and it unifies the full-accuracy and reduced-accuracy paths (the #984 special-case is no longer needed).Runtime verification (before/after)
Drove
getLocation()on a booted iOS simulator with a static Custom Location (simctl location set) and permission granted, via a throwaway integration test asserting completion within 20s:getLocation() did not complete within 20s (hang)→ ❌ failsVERIFY getLocation -> 37.3349, -122.009→ ✅ passesSame repro condition, opposite outcome — confirms both the root cause and the fix. (The test itself is not committed; location-dependent tests are too flaky for CI.) iOS example also
flutter builds clean.Closes
Fixes #798, fixes #955, fixes #1005, fixes #657, fixes #1013
Not auto-closed (possibly related, unconfirmed)
#824(platform unstated, may be Android) and#660(symptom is returns null, not a hang — likely a different cause).Release
Logged under
## Unreleased— no version bump, not for publication yet.