ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: eregontp@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:102300] [Ruby master Bug#17543] Ractor isolation broken by `self` in shareable proc
Date: Fri, 29 Jan 2021 12:31:04 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-90155.20210129123104.182@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-17543.20210115073958.182@ruby-lang.org

Issue #17543 has been updated by Eregon (Benoit Daloze).


ko1 (Koichi Sasada) wrote in #note-10:
> choose `nil` for self for sharable Proc? No special constant is needed.

That sounds confusing, if e.g., the NoMethodError comes from a line like `[foo, bar.foo]`, is it because `self` is nil or because `bar` returns `nil`?
Seems impossible to know if detached self is `nil`.

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

* 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/

  parent reply	other threads:[~2021-01-29 12:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` eregontp [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-90155.20210129123104.182@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).