@@ -588,16 +588,7 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
588
588
ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
589
589
Mutex::ScopedLock lock (w->mutex_ );
590
590
591
- // The object now owns the created thread and should not be garbage collected
592
- // until that finishes.
593
- w->ClearWeak ();
594
-
595
- w->env ()->add_sub_worker_context (w);
596
591
w->stopped_ = false ;
597
- w->thread_joined_ = false ;
598
-
599
- if (w->has_ref_ )
600
- w->env ()->add_refs (1 );
601
592
602
593
uv_thread_options_t thread_options;
603
594
thread_options.flags = UV_THREAD_HAS_STACK_SIZE;
@@ -624,21 +615,27 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
624
615
// implicitly delete w
625
616
});
626
617
}, static_cast <void *>(w));
627
- if (ret != 0 ) {
618
+
619
+ if (ret == 0 ) {
620
+ // The object now owns the created thread and should not be garbage
621
+ // collected until that finishes.
622
+ w->ClearWeak ();
623
+ w->thread_joined_ = false ;
624
+
625
+ if (w->has_ref_ )
626
+ w->env ()->add_refs (1 );
627
+
628
+ w->env ()->add_sub_worker_context (w);
629
+ } else {
630
+ w->stopped_ = true ;
631
+
628
632
char err_buf[128 ];
629
633
uv_err_name_r (ret, err_buf, sizeof (err_buf));
630
- w->custom_error_ = " ERR_WORKER_INIT_FAILED" ;
631
- w->custom_error_str_ = err_buf;
632
- w->loop_init_failed_ = true ;
633
- w->thread_joined_ = true ;
634
- w->stopped_ = true ;
635
- w->env ()->remove_sub_worker_context (w);
636
634
{
637
635
Isolate* isolate = w->env ()->isolate ();
638
636
HandleScope handle_scope (isolate);
639
637
THROW_ERR_WORKER_INIT_FAILED (isolate, err_buf);
640
638
}
641
- w->MakeWeak ();
642
639
}
643
640
}
644
641
0 commit comments