From: "Eregon (Benoit Daloze)" Date: 2021-10-06T18:39:31+00:00 Subject: [ruby-core:105576] [Ruby master Bug#18243] Ractor.make_shareable does not freeze the receiver of a Proc but allows accessing ivars of it Issue #18243 has been updated by Eregon (Benoit Daloze). Smaller repro: ``` $ ruby -e 'Object.new.instance_eval { p object_id; proc = Ractor.make_shareable -> { self }; Ractor.new(proc) { |c| p c.call.object_id }.take }' 60 :267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. 60 ``` In contrast to: ``` $ ruby -e 'a=Object.new; Ractor.make_shareable -> { a }' :816:in `make_shareable': can not make shareable Proc because it can refer unshareable object # from variable `a' (Ractor::IsolationError) from -e:1:in `
' ``` It seems there is no check for `self` but there should be, it's like a capture local variable. Either it raises like for local vars or it `Ractor.make_shareable` the `self`. If it raises ostruct.rb will break but that's fixable by `Ractor.make_shareable self` first which is probably best for clarity anyway, cc @marcandre. ---------------------------------------- Bug #18243: Ractor.make_shareable does not freeze the receiver of a Proc but allows accessing ivars of it https://bugs.ruby-lang.org/issues/18243#change-94034 * Author: Eregon (Benoit Daloze) * Status: Open * Priority: Normal * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- ```ruby c = C.new c.foo = 1 p c proc = c.setter_proc p c.frozen? Ractor.new(proc) { |s| s.call(42) }.take p c ``` gives ``` # false # # BUG ``` But that must be a bug, it means the non-main Ractor can directly mutate an object from the main Ractor. I found this while thinking about https://github.com/ruby/ostruct/pull/29/files and whether `Ractor.make_shareable` would freeze `@table` and the `OpenStruct` instance (I think it needs to). Repro code for ostruct and changing ostruct.rb to `$setter = ::Ractor.make_shareable(setter_proc)`: ```ruby require 'ostruct' os = OpenStruct.new os.foo = 1 $setter.call(2) p os Ractor.new($setter) { |s| s.call(42) }.take p os ``` gives ``` # :267: warning: Ractor is experimental, and the behavior may change in future versions of Ruby! Also there are many implementation issues. # # BUG ``` -- https://bugs.ruby-lang.org/ Unsubscribe: