ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:102102] [Ruby master Bug#17543] Ractor isolation broken by `self` in shareable proc
@ 2021-01-15  7:40 marcandre-ruby-core
  2021-01-15 18:54 ` [ruby-core:102106] " eregontp
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: marcandre-ruby-core @ 2021-01-15  7:40 UTC (permalink / raw)
  To: ruby-core

Issue #17543 has been reported by marcandre (Marc-Andre Lafortune).

----------------------------------------
Bug #17543: Ractor isolation broken by `self` in shareable proc
https://bugs.ruby-lang.org/issues/17543

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* ruby -v: 3.0.0p0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Discussing with @MaxLap we realized that the `self` in a shareable proc is not properly isolated:

```
class Foo
  attr_accessor :x

  def pr
    Ractor.make_shareable(Proc.new { self })
  end
end

f = Foo.new
f.x = [1, 2, 3]
Ractor.new(f.pr) { |pr| pr.call.x << :oops }
p f.x # => [1, 2, 3, :oops]
```

If the `self` refers to a shareable object then it's fine, but for non-shareable objects it has to be reset to `nil` or to a global shareable object that would have an instructive `inspect`.

```ruby
Ractor::DETACHED_SELF = Object.new
def << Ractor::DETACHED_SELF
  def inspect
    '<#detached self>'
  end
  alias to_s inspect
end
Ractor::DETACHED_SELF.freeze
```




-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-08-24 20:34 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15  7:40 [ruby-core:102102] [Ruby master Bug#17543] Ractor isolation broken by `self` in shareable proc marcandre-ruby-core
2021-01-15 18:54 ` [ruby-core:102106] " eregontp
2021-01-16  0:55 ` [ruby-core:102110] " marcandre-ruby-core
2021-01-16 14:40 ` [ruby-core:102112] " eregontp
2021-01-16 16:41 ` [ruby-core:102114] " marcandre-ruby-core
2021-01-16 18:00 ` [ruby-core:102115] " eregontp
2021-01-16 23:45 ` [ruby-core:102117] " marcandre-ruby-core
2021-01-22 16:23 ` [ruby-core:102193] " hunter_spawn
2021-01-22 17:17 ` [ruby-core:102195] " marcandre-ruby-core
2021-01-22 18:00 ` [ruby-core:102196] " eregontp
2021-01-29  9:19 ` [ruby-core:102294] " ko1
2021-01-29 12:31 ` [ruby-core:102300] " eregontp
2021-01-29 15:06 ` [ruby-core:102304] " marcandre-ruby-core
2023-08-24 20:34 ` [ruby-core:114510] " jeremyevans0 (Jeremy Evans) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).