-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src,worker: runtime error on pthread creation failure #32344
Conversation
Instead of assertion failure, now we get a runtime error like this. |
Change looks good. Ideally this would come with a test but given the nature of the failure that's going to be difficult I'd imagine. |
when I was doing testing with this, I found this out: the error was not actually caught by the error handler, instead thrown as unahndled exception.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw error, so the caller can catch?
Yes, I’d suggest doing that.
src/node_worker.cc
Outdated
// Reset the parent port as we're closing it now anyway. | ||
w->object()->Set(w->env()->context(), | ||
w->env()->message_port_string(), | ||
Undefined(w->env()->isolate())).Check(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please return here if the result of Set()
is empty instead of using .Check()
.
src/node_worker.cc
Outdated
w->object()->Set(w->env()->context(), | ||
w->env()->message_port_string(), | ||
Undefined(w->env()->isolate())).Check(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w->object()->Set(w->env()->context(), | |
w->env()->message_port_string(), | |
Undefined(w->env()->isolate())).Check(); | |
w->object()->Set(w->env()->context(), | |
w->env()->message_port_string(), | |
Undefined(w->env()->isolate())).Check(); |
(arguments should line up - but like Anna said, don't use Check().)
src/node_worker.cc
Outdated
Local<Value> args[] = { | ||
Integer::New(w->env()->isolate(), w->exit_code_), | ||
w->custom_error_ != nullptr | ||
? OneByteString(w->env()->isolate(), w->custom_error_).As<Value>() | ||
: Null(w->env()->isolate()).As<Value>(), | ||
!w->custom_error_str_.empty() | ||
? OneByteString(w->env()->isolate(), w->custom_error_str_.c_str()) | ||
.As<Value>() | ||
: Null(w->env()->isolate()).As<Value>(), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this ternary-heave style very hard to read. Can I suggest this?
Isolate* isolate = w->env()->isolate();
HandleScope handle_scope(isolate);
// ...
Local<Value> exit_code_v = Integer::New(isolate, w->exit_code_);
Local<Value> null_v = Null(isolate).As<Value>();
Local<Value> argv[3] = {exit_code_v, null_v, null_v};
if (w->custom_error_ != nullptr)
args[1] = OneByteString(isolate, w->custom_error_);
if (!w->custom_error_str_.empty())
args[2] = OneByteString(isolate, w->custom_error_str_.c_str());
Or alternatively:
Local<Value> exit_code_v = Integer::New(isolate, w->exit_code_);
Local<Value> null_v = Null(isolate).As<Value>();
Local<Value> custom_error_v = null_v;
Local<Value> custom_error_str_v = null_v;
if (w->custom_error_ != nullptr)
custom_error_v = OneByteString(isolate, w->custom_error_);
if (!w->custom_error_str_.empty())
custom_error_str_v = OneByteString(isolate, w->custom_error_str_.c_str());
Local<Value> argv[] = {exit_code_v, custom_error_v, custom_error_str_v};
I've left out the .As<Value>()
casts because I don't think they're necessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fwiw, we don’t need the ternaries here anyway because we already know that custom_error_
and custom_error_str_
are set.
But either way, that should go away if this is converted to throwing an exception.
with large number of worker threads pthread fails with hard assertion. Instead of hard assertion throw a runtime error. Refs: nodejs#32319
831cffc
to
c064d2d
Compare
@addaleax and @bnoordhuis, PTAL. |
src/node_worker.cc
Outdated
HandleScope handle_scope(isolate); | ||
THROW_ERR_WORKER_INIT_FAILED(isolate, err_buf); | ||
} | ||
w->MakeWeak(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
w->MakeWeak(); | |
w->MakeWeak(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bnoordhuis, thanks. Fixed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please revert the file permissions back to 0644
@devsnek, thanks. reverted the file permissions to 644. PTAL. |
Landed in b6459ec |
Instead of setting and then in the case of error un-setting properties, only set them when no error occurs. Refs: nodejs#32344
With large number of worker threads pthread fails with hard assertion. Instead of hard assertion throw a runtime error. PR-URL: nodejs#32344 Fixes: nodejs#32319 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Instead of setting and then in the case of error un-setting properties, only set them when no error occurs. Refs: nodejs#32344 PR-URL: nodejs#32562 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
There’s no reason for this to not be stored alongside the loop data structure itself. PR-URL: nodejs#32562 Refs: nodejs#32344 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
with large number of worker threads,
uv_pthread_create_ex
was failing,that leads to assertion failure. Convert it into a runtime error.
Fixes: #32319
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes