Closed Bug 2048118 Opened 5 months ago Closed 3 months ago

Improve NetworkGeolocationProvider behavior and integration

Categories

(Toolkit :: Geolocation Provider, enhancement)

enhancement

Tracking

()

RESOLVED FIXED
155 Branch
Tracking Status
firefox154 --- fixed
firefox155 --- fixed

People

(Reporter: handyman, Assigned: handyman)

References

Details

Attachments

(8 external files, 6 obsolete files)

The NetworkGeolocationProvider has some issues that cause it to run too frequently which, among other things, is not good for power usage. A list of things I'm looking at here includes:

  1. Coalesce concurrent requests and abort fetch on shutdown. Moderate gain due to reducing waste (fewer network requests).
  2. Persist the request cache beyond shutdown so new requests can hit it as soon as they start. High gain due to frequent cold starts (fewer network requests).
  3. Incrementally increase the retry timer duration while requests are failing. Reset to minimum on each Startup call (clients currently guard against calling twice but don't need to). Moderate improvement in power for clients issuing requests where geolocation is blocked or frequently fails.
  4. Stop active MLS fallback when GeoClue recovers (a one-liner). Mild reduction in network usage.

Add an in-flight guard so the repeating 5s timer and wifi onChange events no
longer stack overlapping network geolocation fetches while a request is slow
or the endpoint is failing. Callers are skipped in favor of reusing
(sufficiently precise) in-flight requests. Also store the AbortController on
the instance and abort any outstanding fetch in shutdown(), so the retry loop
does not outlive the provider.

Stop clearing the cached response in shutdown(), so a recent position can be
reused across the provider's shutdown/restart cycles within a browser run,
avoiding a cold-start network request for each intermittent geolocation use.

Also observes network:link-status-changed and invalidates the cache on "changed"/"up". A
cached location is only valid on the network it came from (GeoIP depends on the
public IP, a wifi fix on the visible access points). The observer lives on the
cache, so invalidation also works while the provider is shut down.

Apply bounded exponential backoff to the repeating request timer after network
failures (increasing up to geo.provider.network.backoffMaxMs, default 20s) so a
failing or unreachable endpoint is not retried every 5s indefinitely, which
drains battery on always-on machines. The backoff is reset to the normal
cadence on a new watch request and on a successful response, so genuine
requests are never delayed by a prior failure's backoff.

UpdateLastPosition only stopped the fallback wait timer, so an MLS fallback
that had already started (e.g. after a GeoClue error) kept running its
NetworkGeolocation provider -- issuing network requests for the rest of the
session -- despite GeoClue producing positions again. Shut down an active
fallback on recovery with "ProviderResponded", matching how CoreLocation and
Portal work.

Reset the NetworkGeolocationProvider failure backoff whenever a different
provider falls back, which can happen multiple times.

Do we have a design doc somewhere where we can talk?

Flags: needinfo?(davidp99)
Flags: needinfo?(davidp99)
Attachment #9603235 - Attachment is obsolete: true
Attachment #9603234 - Attachment is obsolete: true
Attachment #9603236 - Attachment description: Bug 2048118: Part 3 - Back off the NetworkGeolocationProvider retry timer while requests are failing r=saschanaz,jjaschke → Bug 2048118: Part 1 - Back off the NetworkGeolocationProvider retry timer while requests are failing r=saschanaz,jjaschke
Attachment #9603237 - Attachment description: Bug 2048118: Part 4 - Stop active NetworkGeolocationProvider when GeoClue recovers r=saschanaz,jjaschke → Bug 2048118: Part 2 - Stop active NetworkGeolocationProvider when GeoClue recovers r=saschanaz,jjaschke
Attachment #9603238 - Attachment description: Bug 2048118: Part 5 - Reset NetworkGeolocationProvider request backoff on a new request r=saschanaz,jjaschke → Bug 2048118: Part 3 - Reset NetworkGeolocationProvider request backoff on a new request r=saschanaz,jjaschke

Stop clearing gCachedRequest in shutdown() so a recent position can be reused
across the provider's stop/restart cycles within a browser run, instead of
cold-starting a network request for each intermittent geolocation use.

Pushed by daparks@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/8dc47543f04a https://hg.mozilla.org/integration/autoland/rev/96b176e7f711 Part 1 - Back off the NetworkGeolocationProvider retry timer while requests are failing r=saschanaz https://github.com/mozilla-firefox/firefox/commit/a790333c3776 https://hg.mozilla.org/integration/autoland/rev/68c8dbccfb16 Part 2 - Stop active NetworkGeolocationProvider when GeoClue recovers r=saschanaz https://github.com/mozilla-firefox/firefox/commit/67d3887e9bf2 https://hg.mozilla.org/integration/autoland/rev/c6adf7f59917 Part 3 - Reset NetworkGeolocationProvider request backoff on a new request r=saschanaz https://github.com/mozilla-firefox/firefox/commit/0d26e830b113 https://hg.mozilla.org/integration/autoland/rev/1d4b090b0792 Part 4 - Persist the NetworkGeolocationProvider request cache across shutdown r=saschanaz

Apply bounded exponential backoff to the repeating request timer after network
failures (increasing up to geo.provider.network.backoffMaxMs, default 20s) so a
failing or unreachable endpoint is not retried every 5s indefinitely, which
drains battery on always-on machines. The backoff is reset to the normal
cadence on a new watch request and on a successful response, so genuine
requests are never delayed by a prior failure's backoff.

Original Revision: https://phabricator.services.mozilla.com/D309730

Attachment #9616933 - Flags: approval-mozilla-beta?

UpdateLastPosition only stopped the fallback wait timer, so an MLS fallback
that had already started (e.g. after a GeoClue error) kept running its
NetworkGeolocation provider -- issuing network requests for the rest of the
session -- despite GeoClue producing positions again. Shut down an active
fallback on recovery with "ProviderResponded", matching how CoreLocation and
Portal work.

Original Revision: https://phabricator.services.mozilla.com/D309731

Attachment #9616934 - Flags: approval-mozilla-beta?

Reset the NetworkGeolocationProvider failure backoff whenever a different
provider falls back, which can happen multiple times.

Original Revision: https://phabricator.services.mozilla.com/D309732

Attachment #9616935 - Flags: approval-mozilla-beta?

firefox-beta Uplift Approval Request

  • User impact if declined/Reason for urgency: Excessive, wasteful, battery draining and costly use of Google Location Services, especially on Linux.
  • Code covered by automated testing?: yes
  • Fix verified in Nightly?: no
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: The patches affect how the network geolocation cache (primarily used on Linux) is dirtied. The highest risk is believed to be geolocation using slightly stale information, which is minor and not likely to be exposed in nightly.
  • String changes made/needed?: None
  • Is Android affected?: no
Attachment #9616936 - Flags: approval-mozilla-beta?

Stop clearing gCachedRequest in shutdown() so a recent position can be reused
across the provider's stop/restart cycles within a browser run, instead of
cold-starting a network request for each intermittent geolocation use.

Original Revision: https://phabricator.services.mozilla.com/D313338

Attachment #9616933 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9616934 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9616935 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
Attachment #9616936 - Flags: approval-mozilla-beta? → approval-mozilla-beta+
See Also: → 2060572
See Also: → 2070871
Regressions: 2071182
See Also: → 2076922

Apply bounded exponential backoff to the repeating request timer after network
failures (increasing up to geo.provider.network.backoffMaxMs, default 20s) so a
failing or unreachable endpoint is not retried every 5s indefinitely, which
drains battery on always-on machines. The backoff is reset to the normal
cadence on a new watch request and on a successful response, so genuine
requests are never delayed by a prior failure's backoff.

Original Revision: https://phabricator.services.mozilla.com/D309730

Attachment #9678332 - Flags: approval-mozilla-esr115?

UpdateLastPosition only stopped the fallback wait timer, so an MLS fallback
that had already started (e.g. after a GeoClue error) kept running its
NetworkGeolocation provider -- issuing network requests for the rest of the
session -- despite GeoClue producing positions again. Shut down an active
fallback on recovery with "ProviderResponded", matching how CoreLocation and
Portal work.

Original Revision: https://phabricator.services.mozilla.com/D309731

Attachment #9678333 - Flags: approval-mozilla-esr115?

Reset the NetworkGeolocationProvider failure backoff whenever a different
provider falls back, which can happen multiple times.

Original Revision: https://phabricator.services.mozilla.com/D309732

Attachment #9678334 - Flags: approval-mozilla-esr115?

Stop clearing gCachedRequest in shutdown() so a recent position can be reused
across the provider's stop/restart cycles within a browser run, instead of
cold-starting a network request for each intermittent geolocation use.

Original Revision: https://phabricator.services.mozilla.com/D313338

Attachment #9678335 - Flags: approval-mozilla-esr115?
Attachment #9678332 - Flags: approval-mozilla-esr115? → approval-mozilla-esr115+
Attachment #9678333 - Flags: approval-mozilla-esr115? → approval-mozilla-esr115+
Attachment #9678334 - Flags: approval-mozilla-esr115? → approval-mozilla-esr115+
Attachment #9678335 - Flags: approval-mozilla-esr115? → approval-mozilla-esr115+
Attachment #9678332 - Attachment is obsolete: true
Attachment #9678332 - Flags: approval-mozilla-esr115+ → approval-mozilla-esr115-
Attachment #9678333 - Attachment is obsolete: true
Attachment #9678333 - Flags: approval-mozilla-esr115+ → approval-mozilla-esr115-
Attachment #9678334 - Attachment is obsolete: true
Attachment #9678334 - Flags: approval-mozilla-esr115+ → approval-mozilla-esr115-
Attachment #9678335 - Attachment is obsolete: true
Attachment #9678335 - Flags: approval-mozilla-esr115+ → approval-mozilla-esr115-
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: