ruby-dbus
ruby-dbus copied to clipboard
does not work with Ractors (Ruby 3)
A Ractor is a Ruby 3 mechanism for concurrency, where the basic difference to threads is that everything is isolated, except the things that you explicitly want to share.
To make this work, code that runs in a Ractor must conform to certain limitations:
- no
@@class_variables(ruby-dbus:Message#@@serial) - no
@instance_variablesof Modules/Classes (ruby-dbus:DBus#@logger) ENVis not shareable yet (https://bugs.ruby-lang.org/issues/17676), several uses in ruby-dbus for the session bus- (and so on)
It appears fixable but not trivial.
Some snippets to reproduce the problems:
export RUBYLIB=lib
ruby -r dbus -e 'p DBus::ASessionBus.new.proxy.ListNames.first.size' # this works
ruby -r dbus -e 'r = Ractor.new { p DBus::ASessionBus.new.proxy.ListNames.first.size }; r.take' # fails on ENV
ruby -r dbus -e 'r = Ractor.new { p DBus::ASystemBus.new.proxy.ListNames.first.size }; r.take' # fails on class var
# how ENV fails
ruby -e 'r = Ractor.new { p ENV["HOME"] }; r.take'
ruby -e 'r = Ractor.new { env = Ractor.make_shareable(ENV); p env["HOME"] }; r.take'