Skip to content

Commit

Permalink
fixup! src: avoid race condition in tracing code
Browse files Browse the repository at this point in the history
  • Loading branch information
addaleax committed Jan 27, 2019
1 parent 9d65ad3 commit acabd3e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tracing/node_trace_writer.cc
Expand Up @@ -139,6 +139,9 @@ void NodeTraceWriter::FlushPrivate() {
void NodeTraceWriter::Flush(bool blocking) {
Mutex::ScopedLock scoped_lock(request_mutex_);
{
// We need to lock the mutexes here in a nested fashion; stream_mutex_
// protects json_trace_writer_, and without request_mutex_ there might be
// a time window in which the stream state changes?
Mutex::ScopedLock stream_mutex_lock(stream_mutex_);
if (!json_trace_writer_)
return;
Expand Down
1 change: 1 addition & 0 deletions src/tracing/node_trace_writer.h
Expand Up @@ -49,6 +49,7 @@ class NodeTraceWriter : public AsyncTraceWriter {
// as well as json_trace_writer_.
Mutex stream_mutex_;
// Prevents concurrent R/W on state related to write requests.
// If both mutexes are locked, request_mutex_ has to be locked first.
Mutex request_mutex_;
// Allows blocking calls to Flush() to wait on a condition for
// trace events to be written to disk.
Expand Down

0 comments on commit acabd3e

Please sign in to comment.