Bug #18128
closedRactor allows class variables that have been used before
Description
In order to avoid data races, Ractor is not supposed to allow class variables. For example, the following code does not run:
class C
def initialize
@@var = 1
end
end
Ractor.new do
C.new
end.take
#=> can not access class variables from non-main Ractors (Ractor::IsolationError)
This error is expected because of Ractor's rules.
However, there appears to be a bug that lets class variables be accessed in Ractors if they have already been used in the main Ractor. For example, the following code does unexpectedly run:
class C
def initialize
@@var = 1
end
end
C.new
Ractor.new do
C.new
end.take
This program doesn’t detect the problem and runs without an error message. This could potentially pose problems, as it may allow class variables to remain unnoticed in Ractors, which could lead to a data race situation.
Updated by ko1 (Koichi Sasada) over 2 years ago
- Status changed from Open to Closed
Applied in changeset git|6050e3e2a6ce2269c56fa74bc5b75a94d064b61f.
@@cv is not accessible from non-main ractors
Class variables (@@cv) is not accessible from non-main ractors.
But without this patch cached @@cv can be read.
fix [Bug #18128]