Bug #22497
closedReading a frozen Set held by another Ractor's class crashes
Description
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.