Project

General

Profile

Actions

Bug #18128

closed

Ractor allows class variables that have been used before

Added by rm155 (Rohit Menon) over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:105057]

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.

Actions #1

Updated by ko1 (Koichi Sasada) about 1 year 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]

Actions

Also available in: Atom PDF

Like0
Like0