Project

General

Profile

Actions

Bug #18232

closed

Ractor.make_shareable is broken in code loaded with RubyVM::InstructionSequence.load_from_binary

Added by byroot (Jean Boussier) about 3 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.0.2p107, ruby 3.1.0dev
Backport:
[ruby-core:105504]

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


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #18243: Ractor.make_shareable does not freeze the receiver of a Proc but allows accessing ivars of itClosedActions

Updated by byroot (Jean Boussier) about 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) about 3 years ago

FYI the way it currently works for OpenStruct seems buggy on the Ractor side: #18243

Actions #3

Updated by Eregon (Benoit Daloze) about 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) about 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) about 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) about 3 years ago

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

Actions #7

Updated by tenderlovemaking (Aaron Patterson) about 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]

Actions #8

Updated by byroot (Jean Boussier) about 3 years ago

  • Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN to 3.0: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago

  • Backport changed from 3.0: REQUIRED to 3.0: DONE

ruby_3_0 a2fe4b75e4b236ad15778c59ace63006ace53889 merged revision(s) 217df51f0e5d9824ed712a4d175f555d932e44d8.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0