[ruby-core:105575] [Ruby master Bug#18232] Ractor.make_shareable is broken in code loaded with RubyVM::InstructionSequence.load_from_binary
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-10-06 18:38:54 UTC
List:
ruby-core #105575
Issue #18232 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
<internal:ractor>: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 }'
<internal:ractor>:816:in `make_shareable': can not make shareable Proc because it can refer unshareable object #<Object:0x00007fd8bdd8f688> from variable `a' (Ractor::IsolationError)
from -e:1:in `<main>'
```
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 #18232: Ractor.make_shareable is broken in code loaded with RubyVM::InstructionSequence.load_from_binary
https://bugs.ruby-lang.org/issues/18232#change-94033
* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.2p107, ruby 3.1.0dev
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
This was first reported as a Bootsnap bug: https://github.com/Shopify/bootsnap/issues/376
But I reduced it to:
```ruby
source = <<~RUBY
x = :foo
pr = Proc.new { p x }
Ractor.make_shareable(pr)
pr.call
RUBY
RubyVM::InstructionSequence.compile(source).eval # :foo
RubyVM::InstructionSequence.load_from_binary(RubyVM::InstructionSequence.compile(source).to_binary).eval # false
```
The bug is present on both 3.0.2 and 3.1.0-dev. I have no idea what might cause this.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>