ruby-dbus icon indicating copy to clipboard operation
ruby-dbus copied to clipboard

does not work with Ractors (Ruby 3)

Open mvidner opened this issue 3 years ago • 1 comments

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_variables of Modules/Classes (ruby-dbus: DBus#@logger)
  • ENV is 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.

mvidner avatar Mar 09 '22 16:03 mvidner

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'

mvidner avatar Mar 22 '22 14:03 mvidner