Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 797111a

Browse filesBrowse files
committed
src: avoid race condition in tracing code
`json_trace_writer_` is protected by `stream_mutex_`, but one access to it was not guarded by a lock on said mutex. Refs: #25512 PR-URL: #25624 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
1 parent ce28caf commit 797111a
Copy full SHA for 797111a

File tree

Expand file treeCollapse file tree

2 files changed

+10
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-3
lines changed
Open diff view settings
Collapse file

‎src/tracing/node_trace_writer.cc‎

Copy file name to clipboardExpand all lines: src/tracing/node_trace_writer.cc
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,13 @@ void NodeTraceWriter::FlushPrivate() {
138138

139139
void NodeTraceWriter::Flush(bool blocking) {
140140
Mutex::ScopedLock scoped_lock(request_mutex_);
141-
if (!json_trace_writer_) {
142-
return;
141+
{
142+
// We need to lock the mutexes here in a nested fashion; stream_mutex_
143+
// protects json_trace_writer_, and without request_mutex_ there might be
144+
// a time window in which the stream state changes?
145+
Mutex::ScopedLock stream_mutex_lock(stream_mutex_);
146+
if (!json_trace_writer_)
147+
return;
143148
}
144149
int request_id = ++num_write_requests_;
145150
int err = uv_async_send(&flush_signal_);
Collapse file

‎src/tracing/node_trace_writer.h‎

Copy file name to clipboardExpand all lines: src/tracing/node_trace_writer.h
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ class NodeTraceWriter : public AsyncTraceWriter {
4545
// Triggers callback to close async objects, ending the tracing thread.
4646
uv_async_t exit_signal_;
4747
// Prevents concurrent R/W on state related to serialized trace data
48-
// before it's written to disk, namely stream_ and total_traces_.
48+
// before it's written to disk, namely stream_ and total_traces_
49+
// as well as json_trace_writer_.
4950
Mutex stream_mutex_;
5051
// Prevents concurrent R/W on state related to write requests.
52+
// If both mutexes are locked, request_mutex_ has to be locked first.
5153
Mutex request_mutex_;
5254
// Allows blocking calls to Flush() to wait on a condition for
5355
// trace events to be written to disk.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.