@@ -611,16 +611,7 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
611
611
ASSIGN_OR_RETURN_UNWRAP (&w, args.This ());
612
612
Mutex::ScopedLock lock (w->mutex_ );
613
613
614
- // The object now owns the created thread and should not be garbage collected
615
- // until that finishes.
616
- w->ClearWeak ();
617
-
618
- w->env ()->add_sub_worker_context (w);
619
614
w->stopped_ = false ;
620
- w->thread_joined_ = false ;
621
-
622
- if (w->has_ref_ )
623
- w->env ()->add_refs (1 );
624
615
625
616
uv_thread_options_t thread_options;
626
617
thread_options.flags = UV_THREAD_HAS_STACK_SIZE;
@@ -647,21 +638,27 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
647
638
// implicitly delete w
648
639
});
649
640
}, static_cast <void *>(w));
650
- if (ret != 0 ) {
641
+
642
+ if (ret == 0 ) {
643
+ // The object now owns the created thread and should not be garbage
644
+ // collected until that finishes.
645
+ w->ClearWeak ();
646
+ w->thread_joined_ = false ;
647
+
648
+ if (w->has_ref_ )
649
+ w->env ()->add_refs (1 );
650
+
651
+ w->env ()->add_sub_worker_context (w);
652
+ } else {
653
+ w->stopped_ = true ;
654
+
651
655
char err_buf[128 ];
652
656
uv_err_name_r (ret, err_buf, sizeof (err_buf));
653
- w->custom_error_ = " ERR_WORKER_INIT_FAILED" ;
654
- w->custom_error_str_ = err_buf;
655
- w->loop_init_failed_ = true ;
656
- w->thread_joined_ = true ;
657
- w->stopped_ = true ;
658
- w->env ()->remove_sub_worker_context (w);
659
657
{
660
658
Isolate* isolate = w->env ()->isolate ();
661
659
HandleScope handle_scope (isolate);
662
660
THROW_ERR_WORKER_INIT_FAILED (isolate, err_buf);
663
661
}
664
- w->MakeWeak ();
665
662
}
666
663
}
667
664
0 commit comments