Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Issue 2173443002: Fix a race condition in BrowsingDataRemover. (Closed)

Created:
4 years, 5 months ago by msramek
Modified:
4 years, 5 months ago
Reviewers:
Bernhard Bauer
CC:
chromium-reviews, markusheintz_, msramek+watch_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Fix a race condition in BrowsingDataRemover. BrowsingDataRemover::RemoveImpl runs on the UI thread. It schedules several operations on other threads and flips a boolean flag to "true" for each of them. Each operation responds with a callback on the UI thread flipping its flag back to "false" and call NotifyIfDone(), a method that checks if all flags are already false, in which case it reports that the deletion was completed. In addition, NotifyIfDone() is also called at the end of BrowsingDataRemover::RemoveImpl - this is in case that no tasks on other threads were scheduled. Consider the following simplified scenario with arbitrary task "X": BrowsingDataRemover::RemoveImpl() { DCHECK_CURRENTLY_ON(BrowserThread::UI); waiting_for_task_x_ = true; ScheduleTaskX(&OnXDone); // ... NotifyIfDone(); } BrowsingDataRemover::OnXDone() { DCHECK_CURRENTLY_ON(BrowserThread::UI); waiting_for_task_x_ = false; NotifyIfDone(); } While this pattern should only be used if X is on a different thread, consider what would happen if X was on the UI thread and yielded to the UI thread. NotifyIfDone() in OnXDOne() would find all flags false and notify about the deletion being complete. Immediately after, NotifyIfDone() in RemoveImpl() would do the same. The observer would receive two deletion notifications. This is not hypothetical - clearing with remove_mask == REMOVE_COOKIES will run OnClearedDomainReliabilityMonitor() before RemoveImpl() is finished. This CL fixes that by considering the execution of RemoveImpl() as a task of its own, having its own boolean flag to indicate that the body of RemoveImpl() has finished. This was discovered during the implementation of a task scheduler for BrowsingDataRemover in a different CL and will be covered against regression by the tests of that CL. It was not caught by our tests before because BrowsingDataRemoverCompletionObserver that is commonly used in the unittests always unregisters itself after the first callback and thus never spotted the second callback. BUG=630327 Committed: https://crrev.com/2d114cdf706c786e5c9c801bd19d92d7c51aaa9e Cr-Commit-Position: refs/heads/master@{#407154}

Patch Set 1 #

Unified diffs Side-by-side diffs Delta from patch set Stats (+5 lines, -1 line) Patch
M chrome/browser/browsing_data/browsing_data_remover.h View 1 chunk +1 line, -0 lines 0 comments Download
M chrome/browser/browsing_data/browsing_data_remover.cc View 3 chunks +4 lines, -1 line 0 comments Download

Messages

Total messages: 13 (7 generated)
msramek
Hi Bernhard, Please have a look! (I wonder if this could be related to the ...
4 years, 5 months ago (2016-07-21 17:38:30 UTC) #4
Bernhard Bauer
LGTM, thanks! I'm not quite sure if this would cause a crash though, because I ...
4 years, 5 months ago (2016-07-22 14:17:03 UTC) #7
msramek
Thanks! Hmm, true. I got my hopes up... but I'll still watch if any similar ...
4 years, 5 months ago (2016-07-22 14:23:20 UTC) #8
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2173443002/1
4 years, 5 months ago (2016-07-22 14:23:46 UTC) #10
commit-bot: I haz the power
Committed patchset #1 (id:1)
4 years, 5 months ago (2016-07-22 14:27:18 UTC) #11
commit-bot: I haz the power
4 years, 5 months ago (2016-07-22 14:29:52 UTC) #13
Message was sent while issue was closed.
Patchset 1 (id:??) landed as
https://crrev.com/2d114cdf706c786e5c9c801bd19d92d7c51aaa9e
Cr-Commit-Position: refs/heads/master@{#407154}

Powered by Google App Engine
This is Rietveld 408576698