Skip to content

fix(darwin): stop getLocation hanging on sparse location updates - #1052

Merged
Lyokone merged 1 commit into
masterfrom
fix/darwin-getlocation-stale-guard-hang
Jul 14, 2026
Merged

fix(darwin): stop getLocation hanging on sparse location updates#1052
Lyokone merged 1 commit into
masterfrom
fix/darwin-getlocation-stale-guard-hang

Conversation

@Lyokone

@Lyokone Lyokone commented Jul 14, 2026

Copy link
Copy Markdown
Owner

The second root cause behind the iOS "getLocation never completes" cluster

The main-thread PR (#1050) fixed the locationServicesEnabled hang. This fixes a separate root cause with the same symptom.

didUpdateLocations skipped the cached "last known" fix by counting: waitNextLocation = 2 dropped the first two updates, so a one-shot getLocation() 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).

if abs(location.timestamp.timeIntervalSinceNow) > staleLocationThreshold { return }

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:

Code Result
Old (count-based guard) getLocation() did not complete within 20s (hang) → ❌ fails
New (age-based skip) VERIFY getLocation -> 37.3349, -122.009 → ✅ passes

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

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
@Lyokone
Lyokone merged commit 74a5a10 into master Jul 14, 2026
6 checks passed
@Lyokone
Lyokone deleted the fix/darwin-getlocation-stale-guard-hang branch July 14, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant