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: https://github.com/nodejs/node/issues/24129 PR-URL: https://github.com/nodejs/node/pull/25235 Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
86ae2c182b
commit
f39b3e3371
@ -207,9 +207,17 @@ void Agent::AppendTraceEvent(TraceObject* trace_event) {
|
|||||||
id_writer.second->AppendTraceEvent(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) {
|
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_)
|
for (const auto& id_writer : writers_)
|
||||||
id_writer.second->Flush(blocking);
|
id_writer.second->Flush(blocking);
|
||||||
|
@ -104,9 +104,7 @@ class Agent {
|
|||||||
// Writes to all writers registered through AddClient().
|
// Writes to all writers registered through AddClient().
|
||||||
void AppendTraceEvent(TraceObject* trace_event);
|
void AppendTraceEvent(TraceObject* trace_event);
|
||||||
|
|
||||||
void AddMetadataEvent(std::unique_ptr<TraceObject> event) {
|
void AddMetadataEvent(std::unique_ptr<TraceObject> event);
|
||||||
metadata_events_.push_back(std::move(event));
|
|
||||||
}
|
|
||||||
// Flushes all writers registered through AddClient().
|
// Flushes all writers registered through AddClient().
|
||||||
void Flush(bool blocking);
|
void Flush(bool blocking);
|
||||||
|
|
||||||
@ -145,6 +143,8 @@ class Agent {
|
|||||||
ConditionVariable initialize_writer_condvar_;
|
ConditionVariable initialize_writer_condvar_;
|
||||||
uv_async_t initialize_writer_async_;
|
uv_async_t initialize_writer_async_;
|
||||||
std::set<AsyncTraceWriter*> to_be_initialized_;
|
std::set<AsyncTraceWriter*> to_be_initialized_;
|
||||||
|
|
||||||
|
Mutex metadata_events_mutex_;
|
||||||
std::list<std::unique_ptr<TraceObject>> metadata_events_;
|
std::list<std::unique_ptr<TraceObject>> metadata_events_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user