Bug #18933
closedDir.tmpdir implemented in non-Ractor-safe manner
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) over 2 years ago
- File tmpdir.diff tmpdir.diff added
Attached is a possible solution for this
Updated by nobu (Nobuyoshi Nakada) about 2 years ago
In Ruby 3.0, an instance variable also is not accessible from non-main Ractor.
Updated by headius (Charles Nutter) over 1 year 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).
Updated by jeremyevans0 (Jeremy Evans) over 1 year ago
@nobu (Nobuyoshi Nakada) submitted a pull request to fix this upstream: https://github.com/ruby/tmpdir/pull/22
Updated by nobu (Nobuyoshi Nakada) over 1 year ago
- Status changed from Open to Closed
Applied in changeset git|3e605a781970cef365002167634a1b5a176bffcb.
[ruby/tmpdir] [Bug #18933] Make Dir.mktmpdir
Ractor-safe