Project

General

Profile

Actions

Bug #17543

open

Ractor isolation broken by `self` in shareable proc

Added by marcandre (Marc-Andre Lafortune) 11 months ago. Updated 10 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:102102]

Description

Discussing with MaxLap (Maxime Lapointe) we realized that the self in a shareable proc is not properly isolated:

class Foo
  attr_accessor :x

  def pr
    Ractor.make_shareable(Proc.new { self })
  end
end

f = Foo.new
f.x = [1, 2, 3]
Ractor.new(f.pr) { |pr| pr.call.x << :oops }
p f.x # => [1, 2, 3, :oops]

If the self refers to a shareable object then it's fine, but for non-shareable objects it has to be reset to nil or to a global shareable object that would have an instructive inspect.

Ractor::DETACHED_SELF = Object.new
def << Ractor::DETACHED_SELF
  def inspect
    '<#detached self>'
  end
  alias to_s inspect
end
Ractor::DETACHED_SELF.freeze
Actions

Also available in: Atom PDF