[#111712] [Ruby master Feature#19322] Support spawning "private" child processes — "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" <ruby-core@...>
SXNzdWUgIzE5MzIyIGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGtqdHNhbmFrdHNpZGlzIChLSiBUc2Fu
14 messages
2023/01/07
[ruby-core:111834] [Ruby master Bug#17420] Unsafe mutation of $" when doing non-RubyGems require in Ractor
From:
"Eregon (Benoit Daloze) via ruby-core" <ruby-core@...>
Date:
2023-01-16 13:46:29 UTC
List:
ruby-core #111834
Issue #17420 has been updated by Eregon (Benoit Daloze).
@ko1 I believe this needs to be an exception until there is a better solution.
It's likely possible to create a segfault with concurrent mutations of `$"` currently.
And anyway `require` does not work in non-main Ractors, not just `$"` but many other problems (RubyGems' Monitor, any non-shareable constant accessed during loading in that Ractor, etc).
----------------------------------------
Bug #17420: Unsafe mutation of $" when doing non-RubyGems require in Ractor
https://bugs.ruby-lang.org/issues/17420#change-101245
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* ruby -v: ruby 3.0.0dev (2020-12-16T10:12:48Z master a9a7f4d8b8) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
With an empty file `a.rb`:
```
$ ruby --disable-gems -e 'Ractor.new { puts $" }.take'
-e:1:in `block in <main>': can not access global variables $" from non-main Ractors (RuntimeError)
```
That is expected, given the rules for global variables.
```
ruby --disable-gems -e 'Ractor.new { require "./a.rb"; }.take; p $"'
[... , "/home/eregon/a.rb"]
```
Is it OK that the Ractor can do `require`, which does modify `$"`?
I think it's not, and it might lead to segfaults if e.g. the main Ractor mutates `$"` in parallel to some other Ractor doing `require`.
Probably `require` needs to be forbidden in non-main Ractors (it does mutate `$"`, so it's logical), or there needs to be always VM-global synchronization on any access to `$"` (otherwise, segfaults are possible).
The latter doesn't seem reasonable, especially when considering the user might do `$".each { ... }`.
---
Note that RubyGems' `require` does not work on non-main Ractors (pretty much expected given it depends on a lot of global state):
```
$ ruby -e 'Ractor.new { require "./a.rb"; }.take'
<internal:/home/eregon/prefix/ruby-master/lib/ruby/3.0.0/rubygems/core_ext/kernel_require.rb>:37:in `require': can not access non-shareable objects in constant Kernel::RUBYGEMS_ACTIVATION_MONITOR by non-main ractor. (NameError)
```
This probably also has consequences for `autoload`.
Maybe the `zeitwerk` gem can help with the mode to resolve all autoload at once.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/