Issue #22489 has been updated by jamescook83 (James Cook). This is fixed in 4.1.0-preview1 by 99f2ef9c1f (Fix data race in rb_iseq_original_iseq). I couldn't find an existing issue for it in the tracker. I think this can be closed. ---------------------------------------- Bug #22489: RubyVM::InstructionSequence#to_a segfaults or hangs when called on the same iseq from multiple Ractors https://bugs.ruby-lang.org/issues/22489#change-119712 * Author: jamescook83 (James Cook) * Status: Open * ruby -v: ruby 4.0.8 (2026-10-22 revision 60c3d71bfb) +PRISM [arm64-darwin25] * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- ``` # 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) -- https://bugs.ruby-lang.org/