From: "osyoyu (Daisuke Aritomo) via ruby-core" Date: 2025-12-15T09:59:41+00:00 Subject: [ruby-core:124202] [Ruby Bug#21782] Ractor::IsolationError reports incorrect path for constants found through upwards search Issue #21782 has been updated by osyoyu (Daisuke Aritomo). Patch submitted: https://github.com/ruby/ruby/pull/15556 ---------------------------------------- Bug #21782: Ractor::IsolationError reports incorrect path for constants found through upwards search https://bugs.ruby-lang.org/issues/21782#change-115676 * Author: osyoyu (Daisuke Aritomo) * Status: Open * ruby -v: ruby 4.0.0dev (2025-12-15T07:05:21Z master 5a4faaaeb1) +PRISM [arm64-darwin24] * Backport: 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN ---------------------------------------- Ractor::IsolationError is raised when non-main Ractors attempt access to non-shareable constants. The message contains the path to the constant which triggered the violation. However, the path is incorrect when the constant was resolved through recursive search. ## Repro Run the this Ruby program: ```ruby TOPLEVEL = [1] module M def self.f TOPLEVEL end end Ractor.new { M.f }.value ``` ### Expected Raises Ractor::IsolationError reporting that illegal access occured on `Object::TOPLEVEL` or `TOPLEVEL` ``` bug.rb:5:in 'M.f': can not access non-shareable objects in constant Object::TOPLEVEL by non-main Ractor. (Ractor::IsolationError) from bug.rb:9:in 'block in
' ``` ### Actual Raises Ractor::IsolationError reporting that illegal access occured on `M::TOPLEVEL`, which is incorrect. `TOPLEVEL` cannot be accessed as `M::TOPLEVEL`. ``` bug.rb:5:in 'M.f': can not access non-shareable objects in constant M::TOPLEVEL by non-main Ractor. (Ractor::IsolationError) from bug.rb:9:in 'block in
' ``` ## Suspected code This message is constructed in `rb_const_get_0()` defined in variable.c. ```c static VALUE rb_const_get_0(VALUE klass, ID id, int exclude, int recurse, int visibility) { VALUE c = rb_const_search(klass, id, exclude, recurse, visibility); if (!UNDEF_P(c)) { if (UNLIKELY(!rb_ractor_main_p())) { if (!rb_ractor_shareable_p(c)) { rb_raise(rb_eRactorIsolationError, "can not access non-shareable objects in constant %"PRIsVALUE"::%s by non-main Ractor.", rb_class_path(klass), rb_id2name(id)); } } return c; } return rb_const_missing(klass, ID2SYM(id)); } ``` The path part is built as `rb_class_path(klass)`, but `klass` may not be the module/class which the constant belongs, when the constant was found through recursive search in `rb_const_search`. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/