Skip to content
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

Fix dispose without checking #31260

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/node_v8_platform-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "tracing/node_trace_writer.h"
#include "tracing/trace_event.h"
#include "tracing/traced_value.h"
#include "util.h"

namespace node {

Expand Down Expand Up @@ -79,8 +80,15 @@ class NodeTraceStateObserver
};

struct V8Platform {
bool initialize_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jc-lab Can you call this initialized_ and use a default initializer instead of adding a constructor? i.e.

Suggested change
bool initialize_;
bool initialized_ = false;


V8Platform()
: initialize_(false) {}

#if NODE_USE_V8_PLATFORM
inline void Initialize(int thread_pool_size) {
CHECK(!initialize_);
initialize_ = true;
tracing_agent_ = std::make_unique<tracing::Agent>();
node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get());
node::tracing::TracingController* controller =
Expand All @@ -99,6 +107,10 @@ struct V8Platform {
}

inline void Dispose() {
if(!initialize_)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disposing without initializing first sounds like a buggy use case to me. Why do we return instead of aborting here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node/src/env.cc

Line 958 in bd6d651

DisposePlatform();

Here is the part that calls DisposePlatform globally.

If created through CreatePlatform then v8_platform is not initialized.
So should be ignored instead of Aborting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think the state should be maintained in the caller instead of in the callee..

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DrainTasks now run after RunAtExit has run.
Is this order of execution important?
If order is not important, I think can Dispose with AtExit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(!initialize_)
if (!initialized_)

return;
initialize_ = false;

StopTracingAgent();
platform_->Shutdown();
delete platform_;
Expand Down