Project

General

Profile

Bug #17676

Updated by delner (David Elner) 6 months ago

## Background 

 Accessing ENV variables from a Ractor will raise Ractor::IsolationError, as the Hash is non-shareable. 

 ## How to reproduce (Ruby version & script) 

 ``` ruby 
 ractor = Ractor.new do 
  ENV['PATH'] 
 end 
 
 ractor.take 
 ``` 

 ## Expectation and result 

 Ractor raises Ractor::IsolationError for ENV 

 Expect to be able to access ENV variables from Ractors without raising an error. 

 ``` 
 `block in <main>': can not access non-shareable objects in constant Object::ENV by non-main Ractor. (Ractor::IsolationError) 
 ``` 

 ## Additional Notes 

 Attempting to create a shareable copy of ENV currently fails: 

 ```ruby 
 Ractor.make_shareable(ENV, copy: true) 
 # TypeError: cannot freeze ENV 
 # from <internal:ractor>:812:in `freeze' 
 ``` 

 ## Suggested solutions 

 1. If ENV is a mutable hash, make a Ractor-compatible copy of ENV isolated to that Ractor.   

Back