Project

General

Profile

Actions

Bug #18933

closed

Dir.tmpdir implemented in non-Ractor-safe manner

Added by kreynolds (Kelley Reynolds) over 1 year ago. Updated 9 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
[ruby-core:109284]

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

tmpdir.diff (1.77 KB) tmpdir.diff kreynolds (Kelley Reynolds), 07/28/2022 11:57 AM

Updated by kreynolds (Kelley Reynolds) over 1 year ago

Attached is a possible solution for this

Updated by nobu (Nobuyoshi Nakada) over 1 year ago

In Ruby 3.0, an instance variable also is not accessible from non-main Ractor.

Updated by headius (Charles Nutter) 10 months 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 #5

Updated by nobu (Nobuyoshi Nakada) 9 months ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0