Skip to content

Commit

Permalink
[Merge M69] [MessageLoop] Do not schedule sleeps > 1 day
Browse files Browse the repository at this point in the history
Some platforms don't like timeouts > 100,000,000 seconds.

Note: I tried just banning long delays but it didn't work
(https://bugs.chromium.org/p/chromium/issues/detail?id=850450#c4).
And while we could control delays posted by our codebase (and we should
still try to address that), we can't control those set from Javascript.

TBR=​[email protected]

Bug: 850450
Change-Id: Iaf1b983b7af1954412518ed049f6cd0a3f78ba2a
Reviewed-on: https://chromium-review.googlesource.com/1142602
Commit-Queue: Gabriel Charette <[email protected]>
Reviewed-by: kylechar <[email protected]>
Cr-Original-Commit-Position: refs/heads/master@{#576857}(cherry picked from commit 5bd9b57)
Reviewed-on: https://chromium-review.googlesource.com/1150581
Reviewed-by: Gabriel Charette <[email protected]>
Cr-Commit-Position: refs/branch-heads/3497@{#84}
Cr-Branched-From: 271eaf5-refs/heads/master@{#576753}
  • Loading branch information
Gabriel Charette committed Jul 25, 2018
1 parent 05cac71 commit 73635a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 7 additions & 3 deletions base/message_loop/message_loop.cc
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,10 @@ void MessageLoop::ScheduleWork() {
pump_->ScheduleWork();
}

TimeTicks MessageLoop::CapAtOneDay(TimeTicks next_run_time) {
return std::min(next_run_time, recent_time_ + TimeDelta::FromDays(1));
}

bool MessageLoop::DoWork() {
if (!task_execution_allowed_)
return false;
Expand Down Expand Up @@ -502,16 +506,16 @@ bool MessageLoop::DoDelayedWork(TimeTicks* next_delayed_work_time) {
if (next_run_time > recent_time_) {
recent_time_ = TimeTicks::Now(); // Get a better view of Now();
if (next_run_time > recent_time_) {
*next_delayed_work_time = next_run_time;
*next_delayed_work_time = CapAtOneDay(next_run_time);
return false;
}
}

PendingTask pending_task = incoming_task_queue_->delayed_tasks().Pop();

if (incoming_task_queue_->delayed_tasks().HasTasks()) {
*next_delayed_work_time =
incoming_task_queue_->delayed_tasks().Peek().delayed_run_time;
*next_delayed_work_time = CapAtOneDay(
incoming_task_queue_->delayed_tasks().Peek().delayed_run_time);
}

return DeferOrRunPendingTask(std::move(pending_task));
Expand Down
8 changes: 8 additions & 0 deletions base/message_loop/message_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,14 @@ class BASE_EXPORT MessageLoop : public MessagePump::Delegate,
// responsible for synchronizing ScheduleWork() calls.
void ScheduleWork();

// Returns |next_run_time| capped at 1 day from |recent_time_|. This is used
// to mitigate https://crbug.com/850450 where some platforms are unhappy with
// delays > 100,000,000 seconds. In practice, a diagnosis metric showed that
// no sleep > 1 hour ever completes (always interrupted by an earlier
// MessageLoop event) and 99% of completed sleeps are the ones scheduled for
// <= 1 second. Details @ https://crrev.com/c/1142589.
TimeTicks CapAtOneDay(TimeTicks next_run_time);

// MessagePump::Delegate methods:
bool DoWork() override;
bool DoDelayedWork(TimeTicks* next_delayed_work_time) override;
Expand Down

0 comments on commit 73635a1

Please sign in to comment.