Closed Bug 890362 Opened 11 years ago Closed 11 years ago

Delayed tasks posted to the mozilla UI message loop stop working after sleep/wake and process suspend/resume

Categories

(Core :: IPC, defect)

x86_64
Windows 8
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla25

People

(Reporter: bbondy, Assigned: bbondy)

Details

Attachments

(1 file)

Attached patch Patch v1.Splinter Review
We've noticed that events sometimes get lost in Windows 8 especially around touch when there is a computer sleep/wake or process_suspend/process_resume.
We've noticed in Win8 more than we've ever noticed before because the process gets suspended by windows whenever you switch away from it.

In particular if you use:
> MessageLoop::current()->PostDelayedTask(FROM_HERE, mTask, mDelayMs);
And then before mDelayMS is reached your computer sleeps, or the process suspends, you can reproduce mTask never being executed.

After debugging a little I found that inside TimerThread::DoAfterSleep()
 the value for delay (obtained from timer->GetDelay(&delay)) is a very, very large value.
That comes from a uint, so naturally it is an underflow.

After debugging more I found the first occurrence of that underflow to be passed into nsTimerImpl::InitCommon.
And that comes from a call into MessagePump::ScheduleDelayedWork with a parameter of a value that is slightly less than base::TimeTicks::Now().
Inside we calculate delay which contains a uint: delay = aDelayedTime - base::TimeTicks::Now() which underflows.

The value for the next delayed task time (which is passed into MessagePump::ScheduleDelayedWork) is obtained from: MessageLoop::DoDelayedWork but on sleep/wake and process_suspend/process_resume TimeTicks::Now is later than that value.

The fix here is just to prevent an underflow into the uint 'delay' in such a case.

The reproducible problem is fixed with this fix.
Attachment #771423 - Flags: review?(benjamin)
Attachment #771423 - Attachment is patch: true
Attachment #771423 - Attachment mime type: text/x-patch → text/plain
Attachment #771423 - Flags: review?(benjamin) → review+
Please add a comment that you're relying on the TimeDelta constructor initializing to 0, since it looks like you're using it uninitialized.
will do, thanks for the review.
https://hg.mozilla.org/mozilla-central/rev/3f64ceb4d042
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Summary: Delayed tasks posted to the mozilla UI message loop stop working after sleep/wake → Delayed tasks posted to the mozilla UI message loop stop working after sleep/wake and process suspend/resume
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: