From 54ef6c312a2154f26e971af9e4a483d5d377730e Mon Sep 17 00:00:00 2001 From: Luke Gruber Date: Thu, 5 Jun 2025 20:31:45 -0400 Subject: [PATCH] [Bug #21400] Fix rb_bug() when killing current root fiber in non-main thread (#13526) Fixes the following: ```ruby Thread.new { Fiber.current.kill }.join ``` --- bootstraptest/test_fiber.rb | 5 +++++ thread.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/bootstraptest/test_fiber.rb b/bootstraptest/test_fiber.rb index 2614dd13bf..ae809a5936 100644 --- a/bootstraptest/test_fiber.rb +++ b/bootstraptest/test_fiber.rb @@ -37,3 +37,8 @@ assert_normal_exit %q{ assert_normal_exit %q{ Fiber.new(&Object.method(:class_eval)).resume("foo") }, '[ruby-dev:34128]' + +# [Bug #21400] +assert_normal_exit %q{ + Thread.new { Fiber.current.kill }.join +} diff --git a/thread.c b/thread.c index 6928eafe58..4ab36c6cff 100644 --- a/thread.c +++ b/thread.c @@ -1127,6 +1127,10 @@ thread_join(rb_thread_t *target_th, VALUE timeout, rb_hrtime_t *limit) /* OK. killed. */ break; default: + if (err == RUBY_FATAL_FIBER_KILLED) { // not integer constant so can't be a case expression + // root fiber killed in non-main thread + break; + } rb_bug("thread_join: Fixnum (%d) should not reach here.", FIX2INT(err)); } }