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

Issue 610629 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Closed: May 2016
Cc:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 2
Type: Bug



Sign in to add a comment

Threading issue with TraceLog::EnabledStateObserver

Project Member Reported by xiaoche...@chromium.org, May 10 2016

Issue description

TraceLog stores a vector of raw pointers of EnabledStateObserver, and invokes their callbacks synchronously when TraceLog::IsEnabled() state changes. The invocation is intentionally not lock-guarded, allowing callbacks to use TRACE_EVENT macros [1].

This allows simultaneous access to an observer from multiple threads when TraceLog and the observer are managed by different threads, and can cause threading issues. For example, when the callback of an observer is being run, another thread may run the destructor of the observer, resulting use-after-free (see discussion in [2]).

We should introduce a new EnabledStateObserver interface that, when TraceLog::IsEnabled() state changes, the callbacks are run asynchronously as tasks posted back to the thread managing the observer. This ensures that the observer is accessed by a unique thread and eliminates threading issues.

[1] https://codereview.chromium.org/16829002
[2] https://codereview.chromium.org/1916843003
 
Cc: nduca@chromium.org oysteine@chromium.org simonhatch@chromium.org wangxianzhu@chromium.org dsinclair@chromium.org
Components: -Platform>DevTools>Tracing Internals>Tracing
Labels: -Restrict-View-Google
+bunch of tracing folks.
-RVG as there doesn't seem to be anything secret here

The TL;DR problem here is that, with the current API, the observers have to necessarily be indefinitely lived, or it's impossible to avoid races between OnTraceLog{Dis/En}abled and the dtor.
This is a bummer for some clients like the BlameContext and the v8 profiler that are not long lived singletons.

After some discussion w/ xiaochengh@ and skyostil@ looks like the saner thing to do is to post the observer threads on the clients thread using WeakPtr.
Project Member

Comment 2 by bugdroid1@chromium.org, May 11 2016

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

commit 69156980cae08c198a4102dde2a7275f66c4c0c0
Author: xiaochengh <xiaochengh@chromium.org>
Date: Wed May 11 11:04:14 2016

Introduce TraceLog::AsyncEnabledStateObserver

This CL introduces AsyncEnabledStateObserver as a complement of
the potentially thread-unsafe EnabledStateObserver class. The callbacks
of the new class are called asynchronously as separate tasks, eliminating
the possibility of threading issues when TraceLog and observers are managed
in different threads.

In follow-up CLs, some subclasses of EnabledStateObserver will be migrated
to AsyncEnabledStateObserver instead.

BUG= 610629 
TEST=will be added in a follow-up CL

Review-Url: https://codereview.chromium.org/1956323002
Cr-Commit-Position: refs/heads/master@{#392895}

[modify] https://crrev.com/69156980cae08c198a4102dde2a7275f66c4c0c0/base/trace_event/trace_log.cc
[modify] https://crrev.com/69156980cae08c198a4102dde2a7275f66c4c0c0/base/trace_event/trace_log.h

Status: Available (was: Started)
Status: Fixed (was: Available)
I think that after #3 and https://codereview.chromium.org/1975363002/ this issue is fixed. Will reopen if I find something else.

Sign in to add a comment