Descriptiontracing: Fix AddMetadataEvent race in presence of Convertable arguments
crrev.com/1421053002 introduced a TraceLog::AddMetadataEvent method.
This method has a little race, unveiled by crbug.com/559117.
The race happens only when a ConvertableToTraceFormat is passed to
AddMetadataEvent. Explanation of the race:
- AddMetadataEvent takes optional ConvertableToTraceFormat args.
- ConvertableToTraceFormat is RefCounted but not RCThreadSafe.
- AddMetadataEvent acquires the global TraceLog lock_ (which is good)
but does that only after having initialized the trace_event.
- CTTF args are copied into the TraceEvent outside of the TraceLog
lock. The underlying CTTF AddRef/Deref happen outside the lock.
- Later, when we get to AddMetadataEventsWhileLocked we try to
re-AddRef the CTTF args.
At this point TSAN barks because the CTTF refcount is written both
ouside and inside the lock.
The fix is trivial, just anticipate the lock of AddMetadataEvent by
one statement.
BUG=559117
TBR=oysteine@chromium.org
Committed: https://crrev.com/5c0f93b3235b44f0c69b23063fa10e49da067666
Cr-Commit-Position: refs/heads/master@{#369401}
Patch Set 1 #
Messages
Total messages: 13 (7 generated)
|