@@ -189,6 +189,12 @@ static int StartDebugSignalHandler() {
189189
190190const int CONTEXT_GROUP_ID = 1 ;
191191
192+ std::string GetWorkerLabel (node::Environment* env) {
193+ std::ostringstream result;
194+ result << " Worker[" << env->thread_id () << " ]" ;
195+ return result.str ();
196+ }
197+
192198class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
193199 public protocol::FrontendChannel {
194200 public:
@@ -373,10 +379,13 @@ void NotifyClusterWorkersDebugEnabled(Environment* env) {
373379
374380class NodeInspectorClient : public V8InspectorClient {
375381 public:
376- explicit NodeInspectorClient (node::Environment* env) : env_(env) {
382+ explicit NodeInspectorClient (node::Environment* env, bool is_main)
383+ : env_(env), is_main_(is_main) {
377384 client_ = V8Inspector::create (env->isolate (), this );
378385 // TODO(bnoordhuis) Make name configurable from src/node.cc.
379- ContextInfo info (GetHumanReadableProcessName ());
386+ std::string name =
387+ is_main_ ? GetHumanReadableProcessName () : GetWorkerLabel (env);
388+ ContextInfo info (name);
380389 info.is_default = true ;
381390 contextCreated (env->context (), info);
382391 }
@@ -593,6 +602,7 @@ class NodeInspectorClient : public V8InspectorClient {
593602 }
594603
595604 node::Environment* env_;
605+ bool is_main_;
596606 bool running_nested_loop_ = false ;
597607 std::unique_ptr<V8Inspector> client_;
598608 std::unordered_map<int , std::unique_ptr<ChannelImpl>> channels_;
@@ -610,13 +620,23 @@ Agent::Agent(Environment* env)
610620 : parent_env_(env),
611621 debug_options_ (env->options ()->debug_options) {}
612622
613- Agent::~Agent () = default ;
623+ Agent::~Agent () {
624+ if (start_io_thread_async.data == this ) {
625+ start_io_thread_async.data = nullptr ;
626+ // This is global, will never get freed
627+ uv_close (reinterpret_cast <uv_handle_t *>(&start_io_thread_async), nullptr );
628+ }
629+ }
614630
615631bool Agent::Start (const std::string& path,
616- std::shared_ptr<DebugOptions> options) {
632+ std::shared_ptr<DebugOptions> options,
633+ bool is_main) {
634+ if (options == nullptr ) {
635+ options = std::make_shared<DebugOptions>();
636+ }
617637 path_ = path;
618638 debug_options_ = options;
619- client_ = std::make_shared<NodeInspectorClient>(parent_env_);
639+ client_ = std::make_shared<NodeInspectorClient>(parent_env_, is_main );
620640 if (parent_env_->is_main_thread ()) {
621641 CHECK_EQ (0 , uv_async_init (parent_env_->event_loop (),
622642 &start_io_thread_async,
0 commit comments