Actions
Feature #21942
closedAllow reading class variables from non-main Ractors
Feature #21942:
Allow reading class variables from non-main Ractors
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 months ago
I sent a patch here
Updated by tenderlovemaking (Aaron Patterson) 2 months ago
- Assignee set to ractor
Updated by tenderlovemaking (Aaron Patterson) about 2 months ago
- Status changed from Open to Closed
Applied in changeset git|ab32c0e690b805cdaaf264ad4c3421696c588204.
Allow reading cvars from non-main Ractors (#16308)
Today you can read instance variables from non-main Ractors, but many
Rails applications use cvars, and we cannot read them.
For example:
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
This commit changes the semantics of cvars to be the same as instance
variables:
- It's ok to read Ractor shareable objects from the non-main Ractor
- It's NOT ok to write from the non-main Ractor
[Feature #21942]
Actions