From bd13830d0ba1c6ba2d8ffa5dc15c6cb7c4ae2995 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 1 Jun 2019 16:32:46 +0200 Subject: [PATCH] fixup! src: reorganize inspector and diagnostics initialization --- src/env.h | 3 ++- src/node.cc | 1 + src/node_main_instance.cc | 2 +- src/node_worker.cc | 3 +-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/env.h b/src/env.h index 420099db8ec9fe..fb25ee9845d20a 100644 --- a/src/env.h +++ b/src/env.h @@ -799,12 +799,13 @@ class Environment : public MemoryRetainer { void MemoryInfo(MemoryTracker* tracker) const override; void CreateProperties(); + // Should be called before InitializeInspector() + void InitializeDiagnostics(); #if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM // If the environment is created for a worker, pass parent_handle and // the ownership if transferred into the Environment. int InitializeInspector(inspector::ParentInspectorHandle* parent_handle); #endif - void InitializeDiagnostics(); v8::MaybeLocal BootstrapInternalLoaders(); v8::MaybeLocal BootstrapNode(); diff --git a/src/node.cc b/src/node.cc index 3c896eb9d75497..711e9c305553b7 100644 --- a/src/node.cc +++ b/src/node.cc @@ -249,6 +249,7 @@ int Environment::InitializeInspector( } else { inspector_path = argv_.size() > 1 ? argv_[1].c_str() : ""; } + CHECK(!inspector_agent_->IsListening()); // Inspector agent can't fail to start, but if it was configured to listen // right away on the websocket port and fails to bind/etc, this will return diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 5ce1258ebd4d6b..5c84dd64e6fa64 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -194,6 +194,7 @@ std::unique_ptr NodeMainInstance::CreateMainEnvironment( Environment::kOwnsProcessState | Environment::kOwnsInspector)); env->InitializeLibuv(per_process::v8_is_profiling); + env->InitializeDiagnostics(); // TODO(joyeecheung): when we snapshot the bootstrapped context, // the inspector and diagnostics setup should after after deserialization. @@ -204,7 +205,6 @@ std::unique_ptr NodeMainInstance::CreateMainEnvironment( return env; } - env->InitializeDiagnostics(); if (env->RunBootstrapping().IsEmpty()) { *exit_code = 1; } diff --git a/src/node_worker.cc b/src/node_worker.cc index fd5cb6cd6d4a1f..2b07619076cbc3 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -58,7 +58,6 @@ Worker::Worker(Environment* env, per_isolate_opts_(per_isolate_opts), exec_argv_(exec_argv), platform_(env->isolate_data()->platform()), - // XXX(joyeecheung): should this be per_process::v8_is_profiling instead? start_profiler_idle_notifier_(env->profiler_idle_notifier_started()), thread_id_(Environment::AllocateThreadId()), env_vars_(env->env_vars()) { @@ -263,11 +262,11 @@ void Worker::Run() { Debug(this, "Created Environment for worker with id %llu", thread_id_); if (is_stopped()) return; { + env_->InitializeDiagnostics(); #if NODE_USE_V8_PLATFORM && HAVE_INSPECTOR env_->InitializeInspector(inspector_parent_handle_.release()); inspector_started = true; #endif - env_->InitializeDiagnostics(); HandleScope handle_scope(isolate_); AsyncCallbackScope callback_scope(env_.get()); env_->async_hooks()->push_async_ids(1, 0);