Project

General

Profile

Actions

Bug #21782

open

Ractor::IsolationError reports incorrect path for constants found through upwards search

Bug #21782: Ractor::IsolationError reports incorrect path for constants found through upwards search

Added by osyoyu (Daisuke Aritomo) 1 day ago. Updated 1 day ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.0dev (2025-12-15T07:05:21Z master 5a4faaaeb1) +PRISM [arm64-darwin24]
[ruby-core:124201]

Description

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:

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 <main>'

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 <main>'

Suspected code

This message is constructed in rb_const_get_0() defined in variable.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.

Actions

Also available in: PDF Atom