Project

General

Profile

Actions

Bug #22489

closed

RubyVM::InstructionSequence#to_a segfaults or hangs when called on the same iseq from multiple Ractors

Bug #22489: RubyVM::InstructionSequence#to_a segfaults or hangs when called on the same iseq from multiple Ractors

Added by jamescook83 (James Cook) 13 days ago. Updated 13 days ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.8 (2026-10-22 revision 60c3d71bfb) +PRISM [arm64-darwin25]
[ruby-core:127287]

Description

# Several Ractors call InstructionSequence#to_a on the same blocks at once.
# Expected: prints "survived". Actual: segfault, bus error or hang.
# Usage: ruby repro.rb [how many blocks] [lines in each block]
Warning[:experimental] = false

BLOCKS = Integer(ARGV.fetch(0, 400))
LINES = Integer(ARGV.fetch(1, 300))

module Blocks; end
body = "x = [1].map { |v| v + 1 }\n" * LINES
BLOCKS.times { |n| Blocks.module_eval("def self.block_#{n} = proc {\n#{body}}") }

ractors = Array.new(7) do
  Ractor.new do
    BLOCKS.times { |n| RubyVM::InstructionSequence.of(Blocks.send("block_#{n}")).to_a }
  end
end
ractors.each(&:value)
puts "survived"
┌─────────────────────┬──────────────────────────────────────────────┐
│   blocks × lines    │                 6 runs each                  │
├─────────────────────┼──────────────────────────────────────────────┤
│ 400 × 300 (default) │ 5 segfaults, 1 hang                          │
├─────────────────────┼──────────────────────────────────────────────┤
│ 100 × 100           │ 1 segfault, 1 bus error, 3 hangs, 1 survived │
├─────────────────────┼──────────────────────────────────────────────┤
│ 20 × 20             │ 1 hang, 5 survived                           │
├─────────────────────┼──────────────────────────────────────────────┤
│ 5 × 5               │ 6 survived                                   │
├─────────────────────┼──────────────────────────────────────────────┤
│ 1 × 1               │ 6 survived                                   │
└─────────────────────┴──────────────────────────────────────────────┘


I'm working around it with a exclusive file lock around calls to RubyVM::InstructionSequence.of(...) to force the ractors to take turns.


Files

iseq_ractors_crash.txt (2.52 KB) iseq_ractors_crash.txt jamescook83 (James Cook), 10/31/2026 09:03 AM
Actions

Also available in: PDF Atom