From 2a08f7283ed2ca18e25f4b4d19d2f5c6b450c574 Mon Sep 17 00:00:00 2001 From: Luke Gruber Date: Mon, 23 Dec 2024 13:37:56 -0500 Subject: [PATCH] Fix [Bug #20779] Dedicated native thread creation failed bug When a dedicated native thread fails to create (OS can't create more threads), don't add the ruby-level thread to the thread scheduler. If it's added, then next time the thread is scheduled to run it will sleep forever, waiting for a native thread that doesn't exist to pick it up. --- thread_pthread.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/thread_pthread.c b/thread_pthread.c index 357454f9b5..423814cd38 100644 --- a/thread_pthread.c +++ b/thread_pthread.c @@ -2151,10 +2151,13 @@ native_thread_create_dedicated(rb_thread_t *th) rb_ec_initialize_vm_stack(th->ec, vm_stack, vm_stack_word_size); th->sched.context_stack = vm_stack; - // setup - thread_sched_to_ready(TH_SCHED(th), th); - return native_thread_create0(th->nt); + int err = native_thread_create0(th->nt); + if (!err) { + // setup + thread_sched_to_ready(TH_SCHED(th), th); + } + return err; } static void