ChromeBrowserMainParts::SetupMetrics() to PreCreateThreads(). It's currently in PreMainMessageLoopRun because:
// This must occur at PreMainMessageLoopRun because |SetupMetrics()| uses the
// blocking pool, which is disabled until the CreateThreads phase of startup.
SetupMetrics();
but this is no longer true as TaskScheduler is now initialized prior to CreateThreads() (it only starts running after CreateThreads() but it now accepts tasks before :)).
Race snippet below (caught by trying to enable browser_tests on TSAN):
WARNING: ThreadSanitizer: data race (pid=11585)
Write of size 1 at 0x0000106d9bb0 by main thread:
#0 tracked_objects::ScopedTracker::Enable() base/profiler/scoped_tracker.cc:18 (browser_tests+0x42b5508)
#1 ChromeBrowserMainParts::SetupMetrics() chrome/browser/chrome_browser_main.cc:791:7 (browser_tests+0x49d286f)
#2 ChromeBrowserMainParts::PreMainMessageLoopRunImpl() chrome/browser/chrome_browser_main.cc:1431:3 (browser_tests+0x49d6415)
#3 ChromeBrowserMainParts::PreMainMessageLoopRun() chrome/browser/chrome_browser_main.cc:1257:18 (browser_tests+0x49d620f)
#4 content::BrowserMainLoop::PreMainMessageLoopRun() content/browser/browser_main_loop.cc:1153:13 (browser_tests+0x23a6940)
#5 Invoke<content::BrowserMainLoop *> base/bind_internal.h:196:12 (browser_tests+0x23aa285)
#6 MakeItSo<int (content::BrowserMainLoop::*const &)(), content::BrowserMainLoop *> base/bind_internal.h:262 (browser_tests+0x23aa285)
#7 RunImpl<int (content::BrowserMainLoop::*const &)(), const std::__1::tuple<base::internal::UnretainedWrapper<content::BrowserMainLoop> > &, 0> base/bind_internal.h:338 (browser_tests+0x23aa285)
#8 base::internal::Invoker<base::internal::BindState<int (content::BrowserMainLoop::*)(), base::internal::UnretainedWrapper<content::BrowserMainLoop> >, int ()>::Run(base::internal::BindStateBase*) base/bind_internal.h:316 (browser_tests+0x23aa285)
#9 Run base/callback.h:80:12 (browser_tests+0x2a5964e)
#10 content::StartupTaskRunner::RunAllTasksNow() content/browser/startup_task_runner.cc:45 (browser_tests+0x2a5964e)
#11 content::BrowserMainLoop::CreateStartupTasks() content/browser/browser_main_loop.cc:936:25 (browser_tests+0x23a447b)
#12 content::BrowserMainRunnerImpl::Initialize(content::MainFunctionParams const&) content/browser/browser_main_runner.cc:127:17 (browser_tests+0x23aac35)
#13 content::BrowserMain(content::MainFunctionParams const&) content/browser/browser_main.cc:42:32 (browser_tests+0x23a0c90)
#14 content::RunNamedProcessTypeMain(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, content::MainFunctionParams const&, content::ContentMainDelegate*) content/app/content_main_runner.cc:408:14 (browser_tests+0x41fcaa4)
#15 content::ContentMainRunnerImpl::Run() content/app/content_main_runner.cc:687:12 (browser_tests+0x41fd7f7)
#16 content::ContentServiceManagerMainDelegate::RunEmbedderProcess() content/app/content_service_manager_main_delegate.cc:51:32 (browser_tests+0x41fb2af)
#17 service_manager::Main(service_manager::MainParams const&) services/service_manager/embedder/main.cc:469:29 (browser_tests+0x70403fa)
#18 content::ContentMain(content::ContentMainParams const&) content/app/content_main.cc:19:10 (browser_tests+0x41fba4b)
#19 content::BrowserTestBase::SetUp() content/public/test/browser_test_base.cc:271:3 (browser_tests+0x4d51546)
#20 InProcessBrowserTest::SetUp() chrome/test/base/in_process_browser_test.cc:271:20 (browser_tests+0x439d390)
#21 HandleExceptionsInMethodIfSupported<testing::Test, void> third_party/googletest/src/googletest/src/gtest.cc:2455:12 (browser_tests+0x18d8d46)
#22 testing::Test::Run() third_party/googletest/src/googletest/src/gtest.cc:2467 (browser_tests+0x18d8d46)
#23 testing::TestInfo::Run() third_party/googletest/src/googletest/src/gtest.cc:2653:11 (browser_tests+0x18d9d3d)
#24 testing::TestCase::Run() third_party/googletest/src/googletest/src/gtest.cc:2771:28 (browser_tests+0x18da576)
#25 testing::internal::UnitTestImpl::RunAllTests() third_party/googletest/src/googletest/src/gtest.cc:4648:43 (browser_tests+0x18e38b6)
#26 HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> third_party/googletest/src/googletest/src/gtest.cc:2455:12 (browser_tests+0x18e32b4)
#27 testing::UnitTest::Run() third_party/googletest/src/googletest/src/gtest.cc:4256 (browser_tests+0x18e32b4)
#28 RUN_ALL_TESTS third_party/googletest/src/googletest/include/gtest/gtest.h:2237:46 (browser_tests+0x43b85e5)
#29 base::TestSuite::Run() base/test/test_suite.cc:270 (browser_tests+0x43b85e5)
#30 ChromeTestSuiteRunner::RunTestSuite(int, char**) chrome/test/base/chrome_test_launcher.cc:68:38 (browser_tests+0x4224238)
#31 ChromeTestLauncherDelegate::RunTestSuite(int, char**) chrome/test/base/chrome_test_launcher.cc:77:19 (browser_tests+0x422435f)
#32 content::LaunchTests(content::TestLauncherDelegate*, unsigned long, int, char**) content/public/test/test_launcher.cc:520:31 (browser_tests+0x4dade04)
#33 LaunchChromeTests(unsigned long, content::TestLauncherDelegate*, int, char**) chrome/test/base/chrome_test_launcher.cc:149:10 (browser_tests+0x42247c0)
#34 main chrome/test/base/browser_tests_main.cc:21:10 (browser_tests+0x42240fa)
Previous read of size 1 at 0x0000106d9bb0 by thread T20:
#0 tracked_objects::ScopedTracker::ScopedTracker(tracked_objects::Location const&) base/profiler/scoped_tracker.cc:23:7 (browser_tests+0x42b5541)
#1 content::BrowserThread::GetCurrentThreadIdentifier(content::BrowserThread::ID*) content/browser/browser_thread_impl.cc:660:34 (browser_tests+0x23ba5cb)
#2 content::BrowserThreadImpl::Run(base::RunLoop*) content/browser/browser_thread_impl.cc:296:3 (browser_tests+0x23ba390)
#3 base::Thread::ThreadMain() base/threading/thread.cc:338:3 (browser_tests+0x43046a1)
#4 base::(anonymous namespace)::ThreadFunc(void*) base/threading/platform_thread_posix.cc:71:13 (browser_tests+0x42f81e8)
Location is global 'tracked_objects::(anonymous namespace)::g_scoped_profile_mode' of size 1 at 0x0000106d9bb0 (browser_tests+0x0000106d9bb0)
Thread T20 'Chrome_IOThread' (tid=11701, running) created by main thread at:
#0 pthread_create <null> (browser_tests+0x58da23)
#1 base::(anonymous namespace)::CreateThread(unsigned long, bool, base::PlatformThread::Delegate*, base::PlatformThreadHandle*, base::ThreadPriority) base/threading/platform_thread_posix.cc:110:13 (browser_tests+0x42f7b26)
#2 base::PlatformThread::CreateWithPriority(unsigned long, base::PlatformThread::Delegate*, base::PlatformThreadHandle*, base::ThreadPriority) base/threading/platform_thread_posix.cc:193:10 (browser_tests+0x42f79e5)
#3 base::Thread::StartWithOptions(base::Thread::Options const&) base/threading/thread.cc:112:15 (browser_tests+0x4303513)
#4 content::BrowserThreadImpl::StartWithOptions(base::Thread::Options const&) content/browser/browser_thread_impl.cc:404:25 (browser_tests+0x23badfa)
#5 content::BrowserMainLoop::CreateThreads() content/browser/browser_main_loop.cc:1111:49 (browser_tests+0x23a4877)
#6 Invoke<content::BrowserMainLoop *> base/bind_internal.h:196:12 (browser_tests+0x23aa285)
#7 MakeItSo<int (content::BrowserMainLoop::*const &)(), content::BrowserMainLoop *> base/bind_internal.h:262 (browser_tests+0x23aa285)
#8 RunImpl<int (content::BrowserMainLoop::*const &)(), const std::__1::tuple<base::internal::UnretainedWrapper<content::BrowserMainLoop> > &, 0> base/bind_internal.h:338 (browser_tests+0x23aa285)
#9 base::internal::Invoker<base::internal::BindState<int (content::BrowserMainLoop::*)(), base::internal::UnretainedWrapper<content::BrowserMainLoop> >, int ()>::Run(base::internal::BindStateBase*) base/bind_internal.h:316 (browser_tests+0x23aa285)
#10 Run base/callback.h:80:12 (browser_tests+0x2a5964e)
#11 content::StartupTaskRunner::RunAllTasksNow() content/browser/startup_task_runner.cc:45 (browser_tests+0x2a5964e)
#12 content::BrowserMainLoop::CreateStartupTasks() content/browser/browser_main_loop.cc:936:25 (browser_tests+0x23a447b)
#13 content::BrowserMainRunnerImpl::Initialize(content::MainFunctionParams const&) content/browser/browser_main_runner.cc:127:17 (browser_tests+0x23aac35)
#14 content::BrowserMain(content::MainFunctionParams const&) content/browser/browser_main.cc:42:32 (browser_tests+0x23a0c90)
#15 content::RunNamedProcessTypeMain(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, content::MainFunctionParams const&, content::ContentMainDelegate*) content/app/content_main_runner.cc:408:14 (browser_tests+0x41fcaa4)
#16 content::ContentMainRunnerImpl::Run() content/app/content_main_runner.cc:687:12 (browser_tests+0x41fd7f7)
#17 content::ContentServiceManagerMainDelegate::RunEmbedderProcess() content/app/content_service_manager_main_delegate.cc:51:32 (browser_tests+0x41fb2af)
#18 service_manager::Main(service_manager::MainParams const&) services/service_manager/embedder/main.cc:469:29 (browser_tests+0x70403fa)
#19 content::ContentMain(content::ContentMainParams const&) content/app/content_main.cc:19:10 (browser_tests+0x41fba4b)
#20 content::BrowserTestBase::SetUp() content/public/test/browser_test_base.cc:271:3 (browser_tests+0x4d51546)
#21 InProcessBrowserTest::SetUp() chrome/test/base/in_process_browser_test.cc:271:20 (browser_tests+0x439d390)
#22 HandleExceptionsInMethodIfSupported<testing::Test, void> third_party/googletest/src/googletest/src/gtest.cc:2455:12 (browser_tests+0x18d8d46)
#23 testing::Test::Run() third_party/googletest/src/googletest/src/gtest.cc:2467 (browser_tests+0x18d8d46)
#24 testing::TestInfo::Run() third_party/googletest/src/googletest/src/gtest.cc:2653:11 (browser_tests+0x18d9d3d)
#25 testing::TestCase::Run() third_party/googletest/src/googletest/src/gtest.cc:2771:28 (browser_tests+0x18da576)
#26 testing::internal::UnitTestImpl::RunAllTests() third_party/googletest/src/googletest/src/gtest.cc:4648:43 (browser_tests+0x18e38b6)
#27 HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> third_party/googletest/src/googletest/src/gtest.cc:2455:12 (browser_tests+0x18e32b4)
#28 testing::UnitTest::Run() third_party/googletest/src/googletest/src/gtest.cc:4256 (browser_tests+0x18e32b4)
#29 RUN_ALL_TESTS third_party/googletest/src/googletest/include/gtest/gtest.h:2237:46 (browser_tests+0x43b85e5)
#30 base::TestSuite::Run() base/test/test_suite.cc:270 (browser_tests+0x43b85e5)
#31 ChromeTestSuiteRunner::RunTestSuite(int, char**) chrome/test/base/chrome_test_launcher.cc:68:38 (browser_tests+0x4224238)
#32 ChromeTestLauncherDelegate::RunTestSuite(int, char**) chrome/test/base/chrome_test_launcher.cc:77:19 (browser_tests+0x422435f)
#33 content::LaunchTests(content::TestLauncherDelegate*, unsigned long, int, char**) content/public/test/test_launcher.cc:520:31 (browser_tests+0x4dade04)
#34 LaunchChromeTests(unsigned long, content::TestLauncherDelegate*, int, char**) chrome/test/base/chrome_test_launcher.cc:149:10 (browser_tests+0x42247c0)
#35 main chrome/test/base/browser_tests_main.cc:21:10 (browser_tests+0x42240fa)
SUMMARY: ThreadSanitizer: data race base/profiler/scoped_tracker.cc:18 in tracked_objects::ScopedTracker::Enable()
Comment 1 by bugdroid1@chromium.org
, Jul 26 2017