@@ -189,6 +189,12 @@ static int StartDebugSignalHandler() {
189
189
190
190
const int CONTEXT_GROUP_ID = 1 ;
191
191
192
+ std::string GetWorkerLabel (node::Environment* env) {
193
+ std::ostringstream result;
194
+ result << " Worker[" << env->thread_id () << " ]" ;
195
+ return result.str ();
196
+ }
197
+
192
198
class ChannelImpl final : public v8_inspector::V8Inspector::Channel,
193
199
public protocol::FrontendChannel {
194
200
public:
@@ -373,10 +379,13 @@ void NotifyClusterWorkersDebugEnabled(Environment* env) {
373
379
374
380
class NodeInspectorClient : public V8InspectorClient {
375
381
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) {
377
384
client_ = V8Inspector::create (env->isolate (), this );
378
385
// 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);
380
389
info.is_default = true ;
381
390
contextCreated (env->context (), info);
382
391
}
@@ -593,6 +602,7 @@ class NodeInspectorClient : public V8InspectorClient {
593
602
}
594
603
595
604
node::Environment* env_;
605
+ bool is_main_;
596
606
bool running_nested_loop_ = false ;
597
607
std::unique_ptr<V8Inspector> client_;
598
608
std::unordered_map<int , std::unique_ptr<ChannelImpl>> channels_;
@@ -610,13 +620,23 @@ Agent::Agent(Environment* env)
610
620
: parent_env_(env),
611
621
debug_options_ (env->options ()->debug_options) {}
612
622
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
+ }
614
630
615
631
bool 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
+ }
617
637
path_ = path;
618
638
debug_options_ = options;
619
- client_ = std::make_shared<NodeInspectorClient>(parent_env_);
639
+ client_ = std::make_shared<NodeInspectorClient>(parent_env_, is_main );
620
640
if (parent_env_->is_main_thread ()) {
621
641
CHECK_EQ (0 , uv_async_init (parent_env_->event_loop (),
622
642
&start_io_thread_async,
0 commit comments