Actions
Bug #18933
openDir.tmpdir implemented in non-Ractor-safe manner
Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
Description
Background¶
Inside a Ractor, it is expected that generating a temporary directory using Dir.tmpdir
will work. The current implementation uses a number of things which are not considered Rector-safe and will require refactoring.
How to reproduce¶
Ractor.new { Dir.tmpdir }
Expectation and result¶
The result is expected to be something along the lines of "/var/folders/xm/y4c00x0s26sgf_zlnqjh_7800000gn/T"
but instead a Ractor::IsolationError
exception is raised:
3.1.2/lib/ruby/3.1.0/tmpdir.rb:23:in `tmpdir': can not access class variables from non-main Ractors (Ractor::IsolationError)
Suggested solutions¶
- Make cached class variable a shareable constant
- Modify how random values are generated to be Rector-safe
Files
Updated by kreynolds (Kelley Reynolds) 10 months ago
- File tmpdir.diff tmpdir.diff added
Attached is a possible solution for this
Updated by nobu (Nobuyoshi Nakada) 7 months ago
In Ruby 3.0, an instance variable also is not accessible from non-main Ractor.
Updated by headius (Charles Nutter) 16 days ago
Why not just put this in a private constant? I believe that would be Ractor-safe and it would make more sense than a lazy class variable or class instance variable (that's not actually lazy).
Actions
Like0
Like0Like0Like0