[ruby-core:111838] [Ruby master Feature#19346] Add Ractor escape Ractor.disable_isolation_checks! { }

Issue #19346 has been reported by luke-gru (Luke Gruber). ---------------------------------------- Feature #19346: Add Ractor escape Ractor.disable_isolation_checks! { } https://bugs.ruby-lang.org/issues/19346 * Author: luke-gru (Luke Gruber) * Status: Open * Priority: Normal ---------------------------------------- It would be nice to be able to autoload constants inside Ractors. I'm not sure why this is disabled right now because if autoloading is working properly inside threads then my initial thought is that the autoload implementation should work inside Ractors. I guess there's different parts to this: registering the autoload: ```ruby Ractor.new { autoload :MyClass, 'myclass' } ``` Kicking off the autoload require ```ruby Ractor.new { MyClass } ``` This leads to the problem of calling rubygems `require` inside Ractors, as rubygems is not Ractor safe. However, it's thread-safe so it should be able to be ractor safe too (we don't need the ractor isolation checks in rubygems require). What if there was an API: ```ruby Ractor.disable_isolation_checks! do "..." end ``` It would disable all Ractor isolation errors inside the block. Rubygems could be patched easily and other gems too that are thread-safe and use synchronization around the class ivars and constants. Of course it could be abused and would have to be used properly. Well it's just an idea, I'm sure other people have had the same idea before. -- https://bugs.ruby-lang.org/

Issue #19346 has been updated by ko1 (Koichi Sasada). Status changed from Open to Rejected This kind of escape hatch can break the Ractor's assumptions so it is not accepted. For example, we are working on making ractor-local GC and in this case an object can not be reached from other ractors without special sharing logic. BTW rubygems is thread safe because it uses Mutex (and so on) and this kind of synchronizations are only available in a ractor. ---------------------------------------- Feature #19346: Add Ractor escape hatch Ractor.disable_isolation_checks! { } https://bugs.ruby-lang.org/issues/19346#change-101252 * Author: luke-gru (Luke Gruber) * Status: Rejected * Priority: Normal ---------------------------------------- It would be nice to be able to autoload constants inside Ractors. I'm not sure why this is disabled right now because if autoloading is working properly inside threads then my initial thought is that the autoload implementation should work inside Ractors. I guess there's different parts to this: registering the autoload: ```ruby Ractor.new { autoload :MyClass, 'myclass' } ``` Kicking off the autoload require ```ruby Ractor.new { MyClass } ``` This leads to the problem of calling rubygems `require` inside Ractors, as rubygems is not Ractor safe. However, it's thread-safe so it should be able to be ractor safe too (we don't need the ractor isolation checks in rubygems require). What if there was an API: ```ruby Ractor.disable_isolation_checks! do "..." end ``` It would disable all Ractor isolation errors inside the block. Rubygems could be patched easily and other gems too that are thread-safe and use synchronization around the class ivars and constants. Of course it could be abused and would have to be used properly. Well it's just an idea, I'm sure other people have had the same idea before. -- https://bugs.ruby-lang.org/

Issue #19346 has been updated by luke-gru (Luke Gruber). Hi, thank you for replying. Rubygems is thread-safe but it doesn't work calling `require` inside a non-main ractor because the rubygems internal logic doesn't follow strict isolation protocol. ---------------------------------------- Feature #19346: Add Ractor escape hatch Ractor.disable_isolation_checks! { } https://bugs.ruby-lang.org/issues/19346#change-101257 * Author: luke-gru (Luke Gruber) * Status: Rejected * Priority: Normal ---------------------------------------- It would be nice to be able to autoload constants inside Ractors. I'm not sure why this is disabled right now because if autoloading is working properly inside threads then my initial thought is that the autoload implementation should work inside Ractors. I guess there's different parts to this: registering the autoload: ```ruby Ractor.new { autoload :MyClass, 'myclass' } ``` Kicking off the autoload require ```ruby Ractor.new { MyClass } ``` This leads to the problem of calling rubygems `require` inside Ractors, as rubygems is not Ractor safe. However, it's thread-safe so it should be able to be ractor safe too (we don't need the ractor isolation checks in rubygems require). What if there was an API: ```ruby Ractor.disable_isolation_checks! do "..." end ``` It would disable all Ractor isolation errors inside the block. Rubygems could be patched easily and other gems too that are thread-safe and use synchronization around the class ivars and constants. Of course it could be abused and would have to be used properly. Well it's just an idea, I'm sure other people have had the same idea before. -- https://bugs.ruby-lang.org/
participants (2)
-
ko1 (Koichi Sasada)
-
luke-gru (Luke Gruber)