Project

General

Profile

Actions

Bug #17543

closed

Ractor isolation broken by `self` in shareable proc

Added by marcandre (Marc-Andre Lafortune) over 3 years ago. Updated 8 months ago.

Status:
Closed
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

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0