diff --git a/src/node_worker.cc b/src/node_worker.cc index 1a90e3a64fd843..9b35bb7c08d6aa 100644 --- a/src/node_worker.cc +++ b/src/node_worker.cc @@ -136,6 +136,7 @@ void Worker::Run() { TRACE_STR_COPY(name.c_str())); MultiIsolatePlatform* platform = isolate_data_->platform(); CHECK_NE(platform, nullptr); + bool inspector_started = false; Debug(this, "Starting worker with id %llu", thread_id_); { @@ -163,6 +164,9 @@ void Worker::Run() { } if (!is_stopped()) { + StartWorkerInspector(env_.get(), url_); + inspector_started = true; + HandleScope handle_scope(isolate_); Environment::AsyncCallbackScope callback_scope(env_.get()); env_->async_hooks()->push_async_ids(1, 0); @@ -171,7 +175,6 @@ void Worker::Run() { env_->async_hooks()->pop_async_id(1); Debug(this, "Loaded environment for worker %llu", thread_id_); - StartWorkerInspector(env_.get(), url_); } { @@ -232,7 +235,8 @@ void Worker::Run() { env_->stop_sub_worker_contexts(); env_->RunCleanup(); RunAtExit(env_.get()); - WaitForWorkerInspectorToStop(env_.get()); + if (inspector_started) + WaitForWorkerInspectorToStop(env_.get()); { Mutex::ScopedLock stopped_lock(stopped_mutex_);