Project

General

Profile

Actions

Bug #22497

closed

Reading a frozen Set held by another Ractor's class crashes

Bug #22497: Reading a frozen Set held by another Ractor's class crashes

Added by himura467 (Akito Shitara) 7 days ago. Updated 6 days ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127303]

Description

S = Set[].freeze
Ractor.new { S }.join
-e:1: [BUG] rb_objspace_reachable_objects_from_local: set is owned by another Ractor

Class variables and instance variables of classes crash the same way. Ruby 4.0.7 doesn't crash.

Cause

A Ractor that doesn't own the class checks whether S is shareable by traversing it. Since git|f0439cdfa7 (GH-19145), the children of a T_DATA without declarative marking are enumerated with rb_objspace_reachable_objects_from_local(), which rejects an object owned by another Ractor. The commit before it doesn't crash.

Question

I'm still looking for a good fix. Here is what I've tried so far.

Restoring the enumeration from before f0439cdfa7 for foreign objects (the VM-locked rb_objspace_reachable_objects_from()) fixes the crash, but passes that function an object its comment doesn't allow ("obj may be owned by another Ractor (a shareable)").

I also tried having the owner check shareability when assigning instead, but it doesn't seem to be enough: lib/tmpdir.rb freezes Dir::Tmpname::RANDOM after assigning it, which breaks Tempfile in non-main Ractors.


Related issues 1 (1 open — 0 closed)

Is duplicate of Ruby - Bug #22419: [BUG] "rb_objspace_reachable_objects_from_local: set is owned by another Ractor" when a non-main Ractor reads a class instance variable since f0439cdfa7OpenractorActions
Actions

Also available in: PDF Atom