Skip to content
Permalink
Browse files

src: trace_events: fix race with metadata events

Multiple threads may be concurrently adding to the metadata_events list.
Protect access with a mutex.

Fixes: #24129

PR-URL: #25235
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information...
ofrobots authored and addaleax committed Dec 27, 2018
1 parent 354fba1 commit 807e7328323cfe0dc7b2850133a263c72b5e7f88
Showing with 13 additions and 5 deletions.
  1. +10 −2 src/tracing/agent.cc
  2. +3 −3 src/tracing/agent.h
@@ -207,9 +207,17 @@ void Agent::AppendTraceEvent(TraceObject* trace_event) {
id_writer.second->AppendTraceEvent(trace_event);
}

void Agent::AddMetadataEvent(std::unique_ptr<TraceObject> event) {
Mutex::ScopedLock lock(metadata_events_mutex_);
metadata_events_.push_back(std::move(event));
}

void Agent::Flush(bool blocking) {
for (const auto& event : metadata_events_)
AppendTraceEvent(event.get());
{
Mutex::ScopedLock lock(metadata_events_mutex_);
for (const auto& event : metadata_events_)
AppendTraceEvent(event.get());
}

for (const auto& id_writer : writers_)
id_writer.second->Flush(blocking);
@@ -104,9 +104,7 @@ class Agent {
// Writes to all writers registered through AddClient().
void AppendTraceEvent(TraceObject* trace_event);

void AddMetadataEvent(std::unique_ptr<TraceObject> event) {
metadata_events_.push_back(std::move(event));
}
void AddMetadataEvent(std::unique_ptr<TraceObject> event);
// Flushes all writers registered through AddClient().
void Flush(bool blocking);

@@ -145,6 +143,8 @@ class Agent {
ConditionVariable initialize_writer_condvar_;
uv_async_t initialize_writer_async_;
std::set<AsyncTraceWriter*> to_be_initialized_;

Mutex metadata_events_mutex_;
std::list<std::unique_ptr<TraceObject>> metadata_events_;
};

0 comments on commit 807e732

Please sign in to comment.
You can’t perform that action at this time.