Closed Bug 1262386 Opened 8 years ago Closed 8 years ago

TelemetrySession scheduler timeout does not fire right after sleep


(Toolkit :: Telemetry, defect, P1)




Tracking Status
firefox48 --- affected
firefox49 --- fixed


(Reporter: gfritzsche, Assigned: gfritzsche)



(Whiteboard: [measurement:client])


(2 files)

We expected our scheduler timeouts [0] to fire "soon" after sleep, so that e.g. when users put the computer to sleep over night, we can trigger daily pings right after the wakeup.
However, timeouts are still delayed after wakeup for as long as they would have been before sleep.
That means we could record up to 1 hour (the idle tick timer interval) into the new day.

We should either switch to a scheduling mechanism that fires soon after wakeup or - if we can - explicitly trigger scheduler ticks after wakeup.
Priority: P3 → P1
Points: --- → 3
Assignee: nobody → alessio.placitelli
I investigated the issue on Windows and it looks like timers are taking sleep/wake events in account: if a timer expires when the computer is asleep, it fires its callback as soon as it wakes up.

The sleep/wake events are correctly handled in the timers' manager [1], which ends up calling nsTimerImpl::Fire() by dispatching a |nsTimerEvent| if the timer is overdue.

I tested this behaviour with scratchpad by:

- Printing
- Starting a timer with setTimeout [3] with a 5 minutes timeout and printing in the callback.
- Putting my laptop to sleep.
- Waiting 10 minutes and then waking the laptop.
- The callback immediately fires and prints the current timestamp. The difference between the two timestamps matches with the sleep time.

This seems to be a Linux/Mac only issue. I think this is expected to behave as described in comment 0 on Linux (see bug 758848), but I have no idea why that doesn't work on Mac.

[1] -
[2] -
[3] -
Assignee: alessio.placitelli → nobody
Assignee: nobody → gfritzsche
On Mac we get the "wake_notification" correctly:

... but when we get to the timeout check after sleep here:,468

... we hit bug 1204823.
The clock values returned from TimeStamp::Now() do increase during sleep on Windows, but they don't on Mac.
Consequently, we fire the timeouts after the delay passed in absolute time on Windows, but on Mac only after the delay passed in "awake"/"not suspended" time.

For now we can address this by having TelemetrySession listen to the "wake_notification" and triggering a scheduler tick from it.
This still leaves Linux (which apparently doesn't have the "wake_notification" per bug 758848), but it's at least an improvement.
Move TelemetryScheduler.shutdown() next to init() to make init/shutdown comparisons easier to read.
Attachment #8746066 - Flags: review?(alessio.placitelli)
This makes us trigger a scheduler tick when we get the wake notification. If we passed midnight, this will trigger a daily ping and thus a new subsession.
Attachment #8746071 - Flags: review?(alessio.placitelli)
Attachment #8746066 - Flags: review?(alessio.placitelli) → review+
Comment on attachment 8746071 [details] [diff] [review]
Trigger Telemetry scheduler tick after waking up from sleep

Review of attachment 8746071 [details] [diff] [review]:

This looks good, but keep in mind that it might need to be reworked a bit once bug 1145188 lands.
Attachment #8746071 - Flags: review?(alessio.placitelli) → review+
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
You need to log in before you can comment on or make changes to this bug.