-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tracing: refactor tracing state ownership #23781
Conversation
Does the second commit need tests? |
@@ -13,7 +13,8 @@ const { | |||
ERR_INVALID_ARG_TYPE | |||
} = require('internal/errors').codes; | |||
|
|||
if (!hasTracing) | |||
const { isMainThread } = require('internal/worker'); | |||
if (!hasTracing || !isMainThread) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A note about this limitation should be added in tracing.md also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments and questions.
src/env.cc
Outdated
if (!env_->is_main_thread()) { | ||
// Ideally, we’d have a consistent story that treats all threads/Environment | ||
// instances equally here. However, tracing is essentially global, and this | ||
// callback is callback from whichever thread calls `StartTracing()` or |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// callback is callback from whichever thread calls `StartTracing()` or | |
// callback is called from whichever thread calls `StartTracing()` or |
or invoked
or called back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
src/env.cc
Outdated
@@ -182,10 +191,9 @@ Environment::Environment(IsolateData* isolate_data, | |||
|
|||
AssignToContext(context, ContextInfo("")); | |||
|
|||
if (tracing_agent_writer_ != nullptr) { | |||
if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) { | |||
trace_state_observer_.reset(new TrackingTraceStateObserver(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trace_state_observer_.reset(new TrackingTraceStateObserver(this)); | |
trace_state_observer_ = std::make_unique<TrackingTraceStateObserver>(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
As per the conversation in nodejs#22513, this is essentially global, and adding this on the Environment is generally just confusing. Refs: nodejs#22513 Fixes: nodejs#22767
Forbid modifying tracing state from worker threads, either through the built-in module or inspector sessions, since the main thread owns all global state, and at least the `async_hooks` integration is definitely not thread safe in its current state.
cecac2b
to
66094c3
Compare
Landed in d568b53...5d80ae3 |
As per the conversation in #22513, this is essentially global, and adding this on the Environment is generally just confusing. Refs: #22513 Fixes: #22767 PR-URL: #23781 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Forbid modifying tracing state from worker threads, either through the built-in module or inspector sessions, since the main thread owns all global state, and at least the `async_hooks` integration is definitely not thread safe in its current state. PR-URL: #23781 Fixes: #22767 Refs: #22513 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
As per the conversation in #22513, this is essentially global, and adding this on the Environment is generally just confusing. Refs: #22513 Fixes: #22767 PR-URL: #23781 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Forbid modifying tracing state from worker threads, either through the built-in module or inspector sessions, since the main thread owns all global state, and at least the `async_hooks` integration is definitely not thread safe in its current state. PR-URL: #23781 Fixes: #22767 Refs: #22513 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Marking dont-land-on-v11.x until nodejs/build#1542 is fixed |
As per the conversation in #22513, this is essentially global, and adding this on the Environment is generally just confusing. Refs: #22513 Fixes: #22767 PR-URL: #23781 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Forbid modifying tracing state from worker threads, either through the built-in module or inspector sessions, since the main thread owns all global state, and at least the `async_hooks` integration is definitely not thread safe in its current state. PR-URL: #23781 Fixes: #22767 Refs: #22513 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
As per the conversation in #22513, this is essentially global, and adding this on the Environment is generally just confusing. Refs: #22513 Fixes: #22767 PR-URL: #23781 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
Forbid modifying tracing state from worker threads, either through the built-in module or inspector sessions, since the main thread owns all global state, and at least the `async_hooks` integration is definitely not thread safe in its current state. PR-URL: #23781 Fixes: #22767 Refs: #22513 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
src: remove
Environment::tracing_agent_writer()
As per the conversation in Scope of inspector/tracing agents #22513,
this is essentially global, and adding this on the Environment
is generally just confusing.
Refs: Scope of inspector/tracing agents #22513
Fixes: node::Environment::tracing_agent_writer returns nullptr in a worker #22767
tracing: forbid tracing modifications from worker threads
Forbid modifying tracing state from worker threads, either
through the built-in module or inspector sessions, since
the main thread owns all global state, and at least
the
async_hooks
integration is definitely not threadsafe in its current state.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes