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

Issue 1564193002: Fix race in BrowserThread::GetCurrentThreadIdentifier. (Closed)

Created:
4 years, 11 months ago by Anand Mistry (off Chromium)
Modified:
4 years, 10 months ago
Reviewers:
kinuko
CC:
chromium-reviews, darin-cc_chromium.org, jam, chrome-apps-syd-reviews_chromium.org, gab
Base URL:
https://chromium.googlesource.com/chromium/src.git@master
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

Fix races in BrowserThreadImpl, and some related updates. This change fixes two different races: 1. On destruction of BrowserThreadImpl, the thread is removed from the global thread table after it is stopped. The process of stopping the thread destroys the thread's message loop. However, PostTaskHelper accesses the message loop, which races with the stopping thread. Reordering the two operations is not sufficient because it doesn't handle subclasses (i.e. BrowserProcessSubThread) stopping the thread. 2. There's a missing lock in GetCurrentThreadIdentifier when accessing the global thread table. To track whether or not this causes lock contention, a ScopedTracker has been added. The two other changes are: 1. Remove uses of ScopedAllowSingleton. This isn't necessary any more since the relevant objects are leaky. 2. Remove impossible cases in BrowserThreadImpl::Run(). BUG=115540 Committed: https://crrev.com/83e3480a731d95a97ccc1eacd7b3356ded42b0d4 Cr-Commit-Position: refs/heads/master@{#370560}

Patch Set 1 #

Patch Set 2 : V2 #

Patch Set 3 : fix #

Patch Set 4 : For review #

Total comments: 2

Patch Set 5 : Review comment. #

Total comments: 5

Patch Set 6 : Remove useless code. #

Patch Set 7 : Add comment. #

Patch Set 8 : Fix shutdown race. #

Patch Set 9 : Fix tests failures. #

Total comments: 4

Patch Set 10 : Revert to not using thread-local. #

Patch Set 11 : Rebase #

Unified diffs Side-by-side diffs Delta from patch set Stats (+21 lines, -18 lines) Patch
M build/sanitizers/tsan_suppressions.cc View 1 2 3 4 5 6 7 8 9 10 1 chunk +0 lines, -3 lines 0 comments Download
M content/browser/browser_thread_impl.cc View 1 2 3 4 5 6 7 8 9 6 chunks +21 lines, -15 lines 0 comments Download

Messages

Total messages: 33 (8 generated)
Anand Mistry (off Chromium)
WDYT?
4 years, 11 months ago (2016-01-08 05:12:46 UTC) #3
kinuko
The bug itself looks to be old / have existed before my change? But ok ...
4 years, 11 months ago (2016-01-08 08:41:09 UTC) #4
kinuko
I think this is looking good. One nit + I'll take one more look https://codereview.chromium.org/1564193002/diff/60001/content/browser/browser_thread_impl.cc ...
4 years, 11 months ago (2016-01-08 08:43:32 UTC) #5
Anand Mistry (off Chromium)
Honestly, I kinda picked you as a reviewer at random. Feel free to add another ...
4 years, 11 months ago (2016-01-08 09:52:46 UTC) #6
kinuko
A few more questions... https://codereview.chromium.org/1564193002/diff/80001/content/browser/browser_thread_impl.cc File content/browser/browser_thread_impl.cc (right): https://codereview.chromium.org/1564193002/diff/80001/content/browser/browser_thread_impl.cc#newcode311 content/browser/browser_thread_impl.cc:311: if (g_browser_thread.Get().Get() == this) Is ...
4 years, 11 months ago (2016-01-08 11:35:50 UTC) #7
kinuko
Also: can you update the description to note that this used to be racy before ...
4 years, 11 months ago (2016-01-08 14:58:00 UTC) #8
Anand Mistry (off Chromium)
On 2016/01/08 14:58:00, kinuko wrote: > Also: can you update the description to note that ...
4 years, 11 months ago (2016-01-10 23:18:22 UTC) #9
Anand Mistry (off Chromium)
https://codereview.chromium.org/1564193002/diff/80001/content/browser/browser_thread_impl.cc File content/browser/browser_thread_impl.cc (right): https://codereview.chromium.org/1564193002/diff/80001/content/browser/browser_thread_impl.cc#newcode311 content/browser/browser_thread_impl.cc:311: if (g_browser_thread.Get().Get() == this) On 2016/01/08 11:35:50, kinuko wrote: ...
4 years, 11 months ago (2016-01-10 23:18:28 UTC) #10
kinuko
On 2016/01/10 23:18:22, Anand Mistry wrote: > On 2016/01/08 14:58:00, kinuko wrote: > > Also: ...
4 years, 11 months ago (2016-01-11 03:49:59 UTC) #11
kinuko
lgtm https://codereview.chromium.org/1564193002/diff/80001/content/browser/browser_thread_impl.cc File content/browser/browser_thread_impl.cc (right): https://codereview.chromium.org/1564193002/diff/80001/content/browser/browser_thread_impl.cc#newcode311 content/browser/browser_thread_impl.cc:311: if (g_browser_thread.Get().Get() == this) On 2016/01/10 23:18:28, Anand ...
4 years, 11 months ago (2016-01-11 03:52:22 UTC) #12
Anand Mistry (off Chromium)
On 2016/01/11 03:49:59, kinuko wrote: > On 2016/01/10 23:18:22, Anand Mistry wrote: > > On ...
4 years, 11 months ago (2016-01-11 06:50:15 UTC) #13
kinuko
On 2016/01/11 06:50:15, Anand Mistry wrote: > On 2016/01/11 03:49:59, kinuko wrote: > > On ...
4 years, 11 months ago (2016-01-12 07:41:10 UTC) #14
Anand Mistry (off Chromium)
On 2016/01/12 07:41:10, kinuko wrote: > On 2016/01/11 06:50:15, Anand Mistry wrote: > > On ...
4 years, 11 months ago (2016-01-13 06:18:39 UTC) #15
kinuko
On 2016/01/13 06:18:39, Anand Mistry wrote: > On 2016/01/12 07:41:10, kinuko wrote: > > On ...
4 years, 11 months ago (2016-01-13 06:21:53 UTC) #16
Anand Mistry (off Chromium)
On 2016/01/13 06:21:53, kinuko wrote: > On 2016/01/13 06:18:39, Anand Mistry wrote: > > On ...
4 years, 11 months ago (2016-01-19 01:48:13 UTC) #18
Anand Mistry (off Chromium)
Hang on. This introduced a unit test failure. Sigh! On 19 January 2016 at 12:48, ...
4 years, 11 months ago (2016-01-19 01:57:45 UTC) #19
Anand Mistry (off Chromium)
Ok, I fixed the unit tests issue. PTAL.
4 years, 11 months ago (2016-01-19 03:54:10 UTC) #20
kinuko
https://codereview.chromium.org/1564193002/diff/160001/content/browser/browser_thread_impl.cc File content/browser/browser_thread_impl.cc (right): https://codereview.chromium.org/1564193002/diff/160001/content/browser/browser_thread_impl.cc#newcode433 content/browser/browser_thread_impl.cc:433: // On shutdown, the global thread array could have ...
4 years, 11 months ago (2016-01-19 14:27:20 UTC) #21
Anand Mistry (off Chromium)
PTAL. I've taken another look at this code and decided to revert the thread-local part ...
4 years, 11 months ago (2016-01-20 02:49:49 UTC) #23
kinuko
lgtm!
4 years, 11 months ago (2016-01-20 12:17:00 UTC) #24
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1564193002/200001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1564193002/200001
4 years, 11 months ago (2016-01-20 23:38:19 UTC) #27
commit-bot: I haz the power
Committed patchset #11 (id:200001)
4 years, 11 months ago (2016-01-21 02:12:19 UTC) #28
commit-bot: I haz the power
Patchset 11 (id:??) landed as https://crrev.com/83e3480a731d95a97ccc1eacd7b3356ded42b0d4 Cr-Commit-Position: refs/heads/master@{#370560}
4 years, 11 months ago (2016-01-21 02:13:30 UTC) #30
gab
Just stumbled upon this change, this is great thanks :-)! Curious to know where you're ...
4 years, 10 months ago (2016-02-09 17:55:01 UTC) #31
Anand Mistry (off Chromium)
4 years, 10 months ago (2016-02-09 22:51:16 UTC) #33
Message was sent while issue was closed.
On 2016/02/09 17:55:01, gab wrote:
> Just stumbled upon this change, this is great thanks :-)!
> 
> Curious to know where you're tracking the lock contention results as I'm also
> interested in those results for go/lucky-luke.
> 
> Thanks!
> Gab

I'm not keeping track of contention, but it's visible in UMA's profiler section.
Look up "BrowserThread::GetCurrentThreadIdentifier =>". If we consider anything
over 1ms as contention, then it looks like there's ~0.001% contention in
GetCurrentThreadIdentifier(). Take this with a massive grain of salt, since UMA
is not a substitute for real contention tracking.

Powered by Google App Engine
This is Rietveld 408576698