Bug #18232
closedRactor.make_shareable is broken in code loaded with RubyVM::InstructionSequence.load_from_binary
Description
This was first reported as a Bootsnap bug: https://github.com/Shopify/bootsnap/issues/376
But I reduced it to:
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.
Files
Updated by byroot (Jean Boussier) almost 3 years ago
Because OpenStruct was recently changed to use make_shareable
, this bug suddenly became much more problematic. We actually hit it in production.
Updated by Eregon (Benoit Daloze) almost 3 years ago
FYI the way it currently works for OpenStruct seems buggy on the Ractor side: #18243
Updated by Eregon (Benoit Daloze) almost 3 years ago
- Related to Bug #18243: Ractor.make_shareable does not freeze the receiver of a Proc but allows accessing ivars of it added
Updated by Eregon (Benoit Daloze) almost 3 years ago
(this comment was moved to https://bugs.ruby-lang.org/issues/18243, replied to the wrong issue)
Updated by tenderlovemaking (Aaron Patterson) almost 3 years ago
It looks like the outer variables list is being lost when we dump the iseq to binary. AFAICT, that list is only created at compile time. I'll try to make a patch that reconstructs the list on iseq load as well.
Updated by tenderlovemaking (Aaron Patterson) almost 3 years ago
- File 0001-Dump-outer-variables-tables-when-dumping-an-iseq-to-.patch 0001-Dump-outer-variables-tables-when-dumping-an-iseq-to-.patch added
I've attached a patch that fixes this (for me) along with a test. I had to change the information that we dump when dumping an ISeq, so maybe we need to change the binary format version number or something? I'm not sure. Anyway there is also a PR here
Updated by tenderlovemaking (Aaron Patterson) almost 3 years ago
- Status changed from Open to Closed
Applied in changeset git|217df51f0e5d9824ed712a4d175f555d932e44d8.
Dump outer variables tables when dumping an iseq to binary
This commit dumps the outer variables table when dumping an iseq to
binary. This fixes a case where Ractors aren't able to tell what outer
variables belong to a lambda after the lambda is loaded via ISeq.load_from_binary
[Bug #18232] [ruby-core:105504]
Updated by byroot (Jean Boussier) almost 3 years ago
- Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 3.0: REQUIRED
Updated by nagachika (Tomoyuki Chikanaga) almost 3 years ago
- Backport changed from 3.0: REQUIRED to 3.0: DONE
ruby_3_0 a2fe4b75e4b236ad15778c59ace63006ace53889 merged revision(s) 217df51f0e5d9824ed712a4d175f555d932e44d8.