diff options
author | Koichi Sasada <ko1@atdot.net> | 2021-12-17 14:22:14 +0900 |
---|---|---|
committer | Koichi Sasada <ko1@atdot.net> | 2021-12-17 15:46:50 +0900 |
commit | 37bd795cf8bc9681fccaf9b2d42292b14610a310 (patch) | |
tree | 9fcf88eb81175594565290442d6292b4ad0cb527 /test/ruby | |
parent | d524b9dec9859ce307f6f913be46144557e8edbd (diff) |
`ENV` ivars should not be accessible from ractors
The `ENV` object can have instance variables like other objects,
but they should be accessed only on the main ractor.
fix https://github.com/ruby/ruby/pull/5263#issuecomment-995585766
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5288
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_env.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/ruby/test_env.rb b/test/ruby/test_env.rb index 442fc60f7e..87ccd5102b 100644 --- a/test/ruby/test_env.rb +++ b/test/ruby/test_env.rb @@ -1434,6 +1434,36 @@ class TestEnv < Test::Unit::TestCase end; end + def test_ivar_in_env_should_not_be_access_from_non_main_ractors + assert_ractor <<~RUBY + ENV.instance_eval{ @a = "hello" } + assert_equal "hello", ENV.instance_variable_get(:@a) + + r_get = Ractor.new do + ENV.instance_variable_get(:@a) + rescue Ractor::IsolationError => e + e + end + assert_equal Ractor::IsolationError, r_get.take.class + + r_get = Ractor.new do + ENV.instance_eval{ @a } + rescue Ractor::IsolationError => e + e + end + + assert_equal Ractor::IsolationError, r_get.take.class + + r_set = Ractor.new do + ENV.instance_eval{ @b = "hello" } + rescue Ractor::IsolationError => e + e + end + + assert_equal Ractor::IsolationError, r_set.take.class + RUBY + end + if RUBY_PLATFORM =~ /bccwin|mswin|mingw/ def test_memory_leak_aset bug9977 = '[ruby-dev:48323] [Bug #9977]' |