Open Bug 2089250 Opened 14 days ago Updated 2 days ago

Update badge and restart doorhanger may appear days late on macOS because their timers don't advance while the Mac is asleep

Categories

(Toolkit :: Application Update, defect)

defect

Tracking

()

ASSIGNED

People

(Reporter: spohl, Assigned: spohl)

References

Details

Attachments

(1 external file)

When an update finishes downloading or staging, UpdateListener.handleUpdateStagedOrDownloaded schedules the hamburger menu badge after app.update.badgeWaitTime (4 days on release and beta) and the restart doorhanger after promptWaitTime (8 days), using setTimeout.

On macOS, Gecko timers are based on TimeStamp::Now(), which uses mach_absolute_time. Apple documents that this clock "does not increment while the system is asleep". As far as I can tell, TimerThread::DoAfterSleep only wakes the timer thread and doesn't account for the time spent asleep. If that's right, the 4 days only count time the Mac is awake, so a laptop that sleeps overnight might not show the badge for well over a week. @glandium reports that the badge is still not showing 4 days after an update was downloaded.

This hasn't been measured yet. A first step would be to confirm it with a short app.update.badgeWaitTime and a sleep in between.

If it's confirmed, a possible fix would be for UpdateListener to compare Date.now() against updateFirstReadyTime after waking and show the badge or doorhanger once the wall-clock time has passed, rather than relying on the timeout alone. Bug 282013 seems to cover the general timer behavior across sleep.

handleUpdateStagedOrDownloaded in UpdateListener.sys.mjs schedules the badge and doorhanger through addTimeout, which is setTimeout underneath (#152-159). On macOS those timers do not count time spent asleep, which ScheduledTask.sys.mjs already notes and works around by rebuilding its timer from Date.now() on wake_notification.

Fix: Schedule both through ScheduledTask, as createScheduledRestartTasks in UpdatePolicyEnforcer.sys.mjs does. Use absolute targets of updateFirstReadyTime plus badgeWaitTime or promptWaitTime, have clearCallbacks disarm the tasks, and arm the doorhanger task only from the badge callback, so that when both deadlines pass during sleep the badge cannot replace the doorhanger. Add a browser test next to browser_doorhanger_bc_multiUpdate_promptWaitTime.js that sends sleep_notification, waits past short deadlines, then sends wake_notification, following test_ScheduledTask.js.

Suggested severity: S3. The downloaded update still applies on the next restart, but Mac laptop users who sleep the machine daily can go well past the intended 4 and 8 days without being told to restart, which delays security fixes.


If you'd like to provide feedback on this comment, please use the 👍 or 👎 reaction.
If you want to categorize your feedback you can add one of the following tags: ai-triage-{wrong-file, wrong-cause, hallucination, out-of-scope, not-a-bug, wrong-fix, shallow-fix, wrong-severity}.

Needinfo hackbot@mozilla.tld to have a patch generated for this bug, include any questions or directions as needed in your comment.

Assignee: nobody → spohl.mozilla.bugs
Status: NEW → ASSIGNED
See Also: → 2089280
OS: macOS → All
See Also: → 1204823

Mainly a note to self: Jens' changes in bug 1204823 and bug 2090731 should address the badge timer counting only awake time. It looks like we'd still need a smaller change here for the restart doorhanger.

In UpdateListener.handleUpdateStagedOrDownloaded, the badge callback starts the doorhanger timer using the originally calculated difference between the two delays. With a 4-day badge delay and an 8-day doorhanger delay, waking on day 10 should show the badge, but would then start another 4-day wait for the doorhanger.

We should recompute the remaining doorhanger delay from updateFirstReadyTime and the current time when the badge callback runs. Once Jens' changes land, the switch to ScheduledTask should no longer be needed.

See Also: → 2093841
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: