New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 894664 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: Oct 17
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 2
Type: ----



Sign in to add a comment

offline_pages::TaskQueue should never run a task from and AddTask call

Project Member Reported by carl...@google.com, Oct 12

Issue description

The current TaskQueue::AddTask code might immediately run an added task without posting it for later execution. There are (at least one) cases where the original client of a task, which might not even be aware of the task system, might not expect that to happen and so might not be prepared for the possibility that the provided callback might be run during the call chain containing that lead to AddTask. It would be safer to always post-task the execution of Task::Run.

The specific call chain that lead me to realize this is a potential problem is:

RecentTabHelper::WebContentsWasHidden (unaware of the usage of TaskQueue by OfflinePageModelTaskified)
OfflinePageModelTaskified::GetOfflineIdsForClientId
TaskQueue::AddTask
TaskQueue::StartTaskIfAvailable
Task::Run (depending on the implementation, could immediately execute the callback)

WebContentsWasHidden's implementation relies on the current state of RecentTabHelper being unchanged during the call to GetOfflineIdsForClientId, what could happen should the provided callback be executed in the meantime. This is not the case in practice here but that's by chance and not by design.

CC-ing some interested parties to check if there's any concerns about executing this simple change.

 
Project Member

Comment 1 by bugdroid1@chromium.org, Oct 17

The following revision refers to this bug:
  https://chromium.googlesource.com/chromium/src.git/+/d05595293f24591d82ca3fad41079390f70e96ab

commit d05595293f24591d82ca3fad41079390f70e96ab
Author: Carlos Knippschild <carlosk@chromium.org>
Date: Wed Oct 17 00:33:00 2018

TaskQueue always postpones task execution when one is added.

To avoid unexpected side effects to the AddTask callers chain, a task
should never be directly executed due to a call to that method.

Bug:  894664 
Change-Id: I0ae6977f46999164a6d210c39a552870d3fd8ae2
Reviewed-on: https://chromium-review.googlesource.com/c/1278864
Reviewed-by: Filip Gorski <fgorski@chromium.org>
Reviewed-by: Dan H <harringtond@google.com>
Commit-Queue: Carlos Knippschild <carlosk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600209}
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/core/background/pick_request_task_unittest.cc
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/core/offline_page_archiver.cc
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/task/task.cc
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/task/task.h
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/task/task_queue.cc
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/task/task_queue.h
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/task/task_queue_unittest.cc
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/task/task_unittest.cc
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/task/test_task_runner.cc
[modify] https://crrev.com/d05595293f24591d82ca3fad41079390f70e96ab/components/offline_pages/task/test_task_runner.h

Status: Fixed (was: Unconfirmed)

Sign in to add a comment