Actions
Bug #22489
closedRubyVM::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
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 4.0.8 (2026-10-22 revision 60c3d71bfb) +PRISM [arm64-darwin25]
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
Updated by jamescook83 (James Cook) 13 days ago
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.
Updated by byroot (Jean Boussier) 13 days ago
- Status changed from Open to Closed
Actions