Skip to content

Commit ade4ec6

Browse files
HarshithaKPtargos
authored andcommitted
worker: runtime error on pthread creation
With large number of worker threads pthread fails with hard assertion. Instead of hard assertion throw a runtime error. PR-URL: #32344 Fixes: #32319 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 5b1c346 commit ade4ec6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/node_errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ void OnFatalError(const char* location, const char* message);
5858
V(ERR_TRANSFERRING_EXTERNALIZED_SHAREDARRAYBUFFER, TypeError) \
5959
V(ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED, Error) \
6060
V(ERR_VM_MODULE_CACHED_DATA_REJECTED, Error) \
61+
V(ERR_WORKER_INIT_FAILED, Error) \
6162
V(ERR_PROTO_ACCESS, Error)
6263

6364
#define V(code, type) \
@@ -107,6 +108,7 @@ void OnFatalError(const char* location, const char* message);
107108
V(ERR_TRANSFERRING_EXTERNALIZED_SHAREDARRAYBUFFER, \
108109
"Cannot serialize externalized SharedArrayBuffer") \
109110
V(ERR_TLS_PSK_SET_IDENTIY_HINT_FAILED, "Failed to set PSK identity hint") \
111+
V(ERR_WORKER_INIT_FAILED, "Worker initialization failure") \
110112
V(ERR_PROTO_ACCESS, \
111113
"Accessing Object.prototype.__proto__ has been " \
112114
"disallowed with --disable-proto=throw")

src/node_worker.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
625625
uv_thread_options_t thread_options;
626626
thread_options.flags = UV_THREAD_HAS_STACK_SIZE;
627627
thread_options.stack_size = kStackSize;
628-
CHECK_EQ(uv_thread_create_ex(&w->tid_, &thread_options, [](void* arg) {
628+
int ret = uv_thread_create_ex(&w->tid_, &thread_options, [](void* arg) {
629629
// XXX: This could become a std::unique_ptr, but that makes at least
630630
// gcc 6.3 detect undefined behaviour when there shouldn't be any.
631631
// gcc 7+ handles this well.
@@ -646,7 +646,23 @@ void Worker::StartThread(const FunctionCallbackInfo<Value>& args) {
646646
w->JoinThread();
647647
// implicitly delete w
648648
});
649-
}, static_cast<void*>(w)), 0);
649+
}, static_cast<void*>(w));
650+
if (ret != 0) {
651+
char err_buf[128];
652+
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+
{
660+
Isolate* isolate = w->env()->isolate();
661+
HandleScope handle_scope(isolate);
662+
THROW_ERR_WORKER_INIT_FAILED(isolate, err_buf);
663+
}
664+
w->MakeWeak();
665+
}
650666
}
651667

652668
void Worker::StopThread(const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)