Bug #22419
open[BUG] "rb_objspace_reachable_objects_from_local: set is owned by another Ractor" when a non-main Ractor reads a class instance variable since f0439cdfa7
Description
The Rails nightly CI against Ruby master started crashing with [BUG] rb_objspace_reachable_objects_from_local: set is owned by another Ractor in Action Pack and Action View on all of master, YJIT and master-debug. It bisects to f0439cdfa7 ("Remove VM lock from Ractor.make_shareable()", https://github.com/ruby/ruby/pull/19145): reading a class instance variable that holds a frozen Set created on the main Ractor from a non-main Ractor crashes.
The crash happens where a non-main Ractor reads class-level state such as AbstractController::Base.action_methods (a frozen Set memoized in a class instance variable) and Mime::Type's registry:
https://buildkite.com/rails/rails-nightly/builds/4809#01a11d51-060e-49c8-bdca-6fb5497b1ed1/L1976
The full log of that Action Pack job is attached (rails-nightly_build_4809_actionpack-master.log.zip).
It can be reproduced with a single Action Pack test:
cd actionpack && bin/test test/controller/base_test.rb -i test_action_methods_is_ractor_safe_by_default
Steps to reproduce¶
class C
@s = Set[1, 2].freeze
class << self; attr_reader :s; end
end
p Ractor.new { C.s.include?(1) }.value
Expected behavior¶
$ ruby -v
ruby 4.1.0dev (2026-10-06T21:11:37Z master e8964f3aa3) +PRISM [x86_64-linux]
$ ruby rep.rb
rep.rb:5: warning: Ractor API is experimental and may change in future versions of Ruby.
true
Actual behavior¶
$ ruby -v
ruby 4.1.0dev (2026-10-06T22:31:56Z master f0439cdfa7) +PRISM [x86_64-linux]
$ ruby rep.rb
rep.rb:5: warning: Ractor API is experimental and may change in future versions of Ruby.
rep.rb:5: [BUG] rb_objspace_reachable_objects_from_local: set is owned by another Ractor
ruby 4.1.0dev (2026-10-06T22:31:56Z master f0439cdfa7) +PRISM [x86_64-linux]
-- Ruby level backtrace information ----------------------------------------
rep.rb:5:in 'block in <main>'
-- Threading information ---------------------------------------------------
Total ractor count: 2
Ruby thread count for this ractor: 1
-- C level backtrace information -------------------------------------------
ruby(rb_print_backtrace+0x11) vm_dump.c:1117
ruby(rb_vm_bugreport) vm_dump.c:1483
ruby(rb_bug_without_die_internal+0xbe) error.c:1150
ruby(rb_bug) error.c:1168
ruby(...) gc.c:5948
ruby(obj_traverse_reachable+0x2b) ractor.c:1687
ruby(obj_traverse_i) ractor.c:1825
ruby(rb_obj_traverse+0x2c) ractor.c:1875
ruby(rb_ractor_shareable_p_continue) ractor.c:2081
ruby(rb_ractor_shareable_p+0x1b) ./include/ruby/ractor.h:280
ruby(rb_ractor_shareable_p) ./include/ruby/ractor.h:269
ruby(rb_ivar_lookup) variable.c:1626
ruby(vm_sendish+0xae) vm_insnhelper.c:6285
...
Files
Updated by luke-gru (Luke Gruber) about 1 hour ago
- Assignee set to ractor