Project

General

Profile

Actions

Feature #21942

open

Allow reading class variables from non-main Ractors

Feature #21942: Allow reading class variables from non-main Ractors

Added by tenderlovemaking (Aaron Patterson) 2 days ago. Updated 2 days ago.

Status:
Open
Assignee:
Target version:
-
[ruby-core:124924]

Description

It's very common in Rails applications to use class variables, and today class variables aren't even allowed to be read inside a Ractor:

class Foo
  # This is NOT allowed to be read in non-main Ractors
  @@bar = 123
  def self.bar; @@bar; end

  # This is allowed to be read in non-main Ractors
  @baz = 123
  def self.baz; @baz; end
end

# This is OK
Ractor.new {
  p Foo.baz
}.value

# Exception here
Ractor.new {
  p Foo.bar
}.value

Output is like this:

test.rb:4:in 'Foo.bar': can not access class variables from non-main Ractors (@@bar from Foo) (Ractor::IsolationError)
	from test.rb:10:in 'block in <main>'

Can we allow shareable values to cross the Ractor boundary, similar to class instance variables?

Just for reference, the Rails code in question is here.

Updated by tenderlovemaking (Aaron Patterson) 2 days ago Actions #2

  • Assignee set to ractor
Actions

Also available in: PDF Atom