[#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:112017] [Ruby master Bug#19369] Small corner-case issue that breaks Ractor isolation: change cloned object from another thread
From:
"hsbt (Hiroshi SHIBATA) via ruby-core" <ruby-core@...>
Date:
2023-01-25 03:26:48 UTC
List:
ruby-core #112017
Issue #19369 has been updated by hsbt (Hiroshi SHIBATA).
Status changed from Open to Assigned
Assignee set to ko1 (Koichi Sasada)
----------------------------------------
Bug #19369: Small corner-case issue that breaks Ractor isolation: change cloned object from another thread
https://bugs.ruby-lang.org/issues/19369#change-101450
* Author: luke-gru (Luke Gruber)
* Status: Assigned
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
I was looking into how objects are traversed for deep cloning and I came up with a way to break it. I don't think it'll ever happen in real life so it's not really an issue, just
an interesting case. Run with warnings disabled.
```ruby
obj = Object.new
p "unshareable obj:", obj
UNSHAREABLE = obj
GO = false
SET = false
class Object
attr_accessor :unshareable
def initialize_clone(orig)
puts "Clone called for #{orig.inspect}, self = #{self.inspect}"
_self = self
if orig == UNSHAREABLE
t = Thread.new do
puts "In thread"
Thread.pass until GO
puts "Setting unshareable!"
# this must be done in separate thread to bypass object traversal deep-cloning
_self.unshareable = UNSHAREABLE
Object.const_set(:SET, true)
end
end
super(orig)
end
end
r = Ractor.new(obj) do |o|
puts "from r#{Ractor.current.object_id} obj #{o.inspect}"
GO = true
loop until SET
p "from ractor, got unshareable:", o.unshareable
end
r.take
```
--
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/