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

Issue 862582 link

Starred by 1 user

Issue metadata

Status: Fixed
Closed: Jul 12
EstimatedDays: ----
NextAction: ----
OS: Linux , Android , Windows , Chrome , Mac , Fuchsia
Pri: 1
Type: Bug

Sign in to add a comment

TaskSchedulerSingleThreadTaskRunnerManagerStartTest.PostTaskBeforeStart flaky on Fuchsia x64

Project Member Reported by, Jul 11

Issue description

In try this flaked with:

[ RUN      ] TaskSchedulerSingleThreadTaskRunnerManagerStartTest.PostTaskBeforeStart
[80448:6893521:0709/] Check failed: !should_exit_.IsSet().
#00: base::debug::StackTrace::StackTrace(unsigned long) at ../../base/debug/
#01: endl<char, std::__2::char_traits<char> > at ../../buildtools/third_party/libc++/trunk/include/ostream:1001
      (inlined by) operator<< at ../../buildtools/third_party/libc++/trunk/include/ostream:195
      (inlined by) ~LogMessage at ../../base/
#02: WakeUp at ../../base/task_scheduler/
#03: Release at ../../base/memory/ref_counted.h:385
      (inlined by) Release at ../../base/memory/scoped_refptr.h:284
      (inlined by) ~scoped_refptr at ../../base/memory/scoped_refptr.h:208
      (inlined by) Start at ../../base/task_scheduler/
#04: TestBody at ../../base/task_scheduler/
#05: os_stack_trace_getter at ../../third_party/googletest/src/googletest/src/
      (inlined by) Run at ../../third_party/googletest/src/googletest/src/
#06: os_stack_trace_getter at ../../third_party/googletest/src/googletest/src/
      (inlined by) Run at ../../third_party/googletest/src/googletest/src/
#07: Run at ../../third_party/googletest/src/googletest/src/
#08: RunAllTests at ../../third_party/googletest/src/googletest/src/
#09: Run at ./../../third_party/googletest/src/googletest/src/
#10: RUN_ALL_TESTS at ../../third_party/googletest/src/googletest/include/gtest/gtest.h:2329
      (inlined by) Run at ../../base/test/
#11: Run at ../../base/callback.h:99
      (inlined by) LaunchUnitTestsInternal at ../../base/test/launcher/
#12: LaunchUnitTests at ../../base/test/launcher/
#13: main at ../../base/test/
#14: pc 0x6f412a940e0e (,0x19e0e)
[00046.315] pkgsvr: 2018/07/09 18:38:24 pkgfs:unsupported(/packages/base_unittests/0): dir unlink "app.log"

[00046.325] pkgsvr: 2018/07/09 18:38:24 pkgfs:unsupported(/packages/base_unittests/0): dir unlink "app.log"
[1653/3112] TaskSchedulerSingleThreadTaskRunnerManagerStartTest.PostTaskBeforeStart (CRASHED)

Note that there are already test-ordering-dependent ASAN reports in  issue 763055  and  issue 763100 , and an Android+ASAN report in issue 754676, although those look to have (in principle) been resolved by robliao@'s
Status: Started (was: Untriaged)
Looks like what's happening here is:

1. SingleThreadTaskRunner is created and added to the manager's |workers_|.
2. Task is posted to the new TaskRunner. The posted task takes a reference to the SingleThreadTaskRunner on which it will run.
3. Start() is called on the manager. There is one entry in |workers_|, for which:
4. Manager calls Start() on the worker, causing a new thread to be created and started.
5. This new thread immediately starts running tasks. Once the task posted above has run, the final reference to the SingleThreadTaskRunner is dropped, and the CleanUp() is called on its |worker_|, resulting in |should_exit_.Set()|.
6. Manager calls WakeUp() on the worker, which sees |should_exit_.IsSet()|. Kaboom.

Since Start() will create the worker thread, which will call GetWork() before falling-back to waiting for work to do, the call to WakeUp() is redundant, and as described above, is actively harmful, so we should remove it.
Labels: OS-Android OS-Chrome OS-Linux OS-Mac OS-Windows
Project Member

Comment 3 by, Jul 12

The following revision refers to this bug:

commit 291f0a739f2c952d402f76d3750b9a2340269c18
Author: Wez <>
Date: Thu Jul 12 19:42:09 2018

Fix race-condition in SchedulerSingleThreadTaskRunnerManager::Start().

SchedulerSingleThreadTaskRunnerManager allows SingleThreadTaskRunners to
be created and tasks posted to them before the worker threads are
actually started. The call to Start() the required workers was calling
both Start() and WakeUp() on each of them, the latter being unnecessary
since if a worker needs to process work then it must already have been
woken, when the work was PostTask()d into it.

Besides removing an unnecessary wake-up, this resolves a subtle race-
condition between wake-up and a potential worker clean-up (see bug).

Bug:  862582 
Change-Id: I9c4246cec4b1bda6d728e5e1656bb2c5ca7c0f0a
Commit-Queue: Wez <>
Reviewed-by: Robert Liao <>
Reviewed-by: Gabriel Charette <>
Cr-Commit-Position: refs/heads/master@{#574681}

Status: Fixed (was: Started)

Sign in to add a comment