[#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:111972] [Ruby master Bug#19368] Ractor.make_shareable issue/inconsistency when proc has been run that acesses outers through eval
From:
"luke-gru (Luke Gruber) via ruby-core" <ruby-core@...>
Date:
2023-01-22 18:04:58 UTC
List:
ruby-core #111972
Issue #19368 has been updated by luke-gru (Luke Gruber).
Hopefully this illustrates this small, weird issue a bit more:
```ruby
fails = 0
a = Object.new # non-shareable value
pr_maker = Ractor.current.instance_eval do
Proc.new do
Proc.new do |sym| # line 'x', let's call it. See below.
if sym == :eval
p 'evaling'
eval('a')
else
p 'not evaling'
end
end
end
end
PROC = pr_maker.call # so we can access in non-main ractor, we set constant
Ractor.make_shareable(PROC)
begin
PROC.call(:eval) # this gives error, the proc is now isolated. That's good. It shouldn't be
# a SyntaxError, but so far so good. Ruby also sets a flag on the compilation node of line 'x' that it accesses outers.
rescue SyntaxError => e
fails +=1 if e.message.match?(/can not access variable `a' from isolated Proc/)
end
p fails
# The flag is actually set somewhere during compilation, not on the proc object. If we
# make a new proc, the issue stays the same.
PROC = pr_maker.call
# can't make it shareable now, even though it won't access outer if called without :eval symbol
# This error should be during runtime of the proc, not statically on the nodes themselves.
Ractor.make_shareable(PROC)
fails += Ractor.new do
fails = 0
begin
PROC.call(:no_eval) # this doesn't work, and it should
rescue SyntaxError => e
fails +=1 if e.message.match?(/can not access variable `a' from isolated Proc/)
end
fails
end.take
fails
p fails
```
----------------------------------------
Bug #19368: Ractor.make_shareable issue/inconsistency when proc has been run that acesses outers through eval
https://bugs.ruby-lang.org/issues/19368#change-101406
* Author: luke-gru (Luke Gruber)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
```
a = Object.new # non-shareable
prok = Ractor.current.instance_eval do
Proc.new do
eval('a')
end
end
prok.call # this should work, we're in the main ractor and the proc is not isolated
Ractor.make_shareable(prok) # this doesn't currently work, but I think it should. It gives Ractor::IsolationError. See below for reasoning on why I think it should work.
# A flag seems to be set on the proc after it's run and accesses outers...
```
Because this work fine:
```ruby
a = Object.new # non-shareable
prok = Ractor.current.instance_eval do
Proc.new do
eval('a')
end
end
Ractor.make_shareable(prok) # this works, and it's okay because we get a different error when actually running the shareable proc inside a ractor that accesses outers through eval.
```
--
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/