[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
```
This commit is contained in:
Luke Gruber 2025-06-05 20:31:45 -04:00 committed by GitHub
parent 86eb5f9c05
commit 54ef6c312a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
Notes: git 2025-06-06 00:31:58 +00:00
Merged-By: ioquatix <samuel@codeotaku.com>
2 changed files with 9 additions and 0 deletions

View File

@ -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
}

View File

@ -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));
}
}