Project

General

Profile

Actions

Bug #22378

closed

`Ractor::IsolationError` in code not using Ractors

Bug #22378: `Ractor::IsolationError` in code not using Ractors

Added by Earlopain (Earlopain _) 3 days ago. Updated 1 day ago.

Status:
Closed
Assignee:
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-09-23T07:42:54Z master 8cdc7b5957) +PRISM [x86_64-linux]
[ruby-core:126842]

Description

# Reduced from the `httpx` gem
@var = Class.new.freeze.dup
@var.instance_variable_set(:@test, 123)

I expect this code to succeed. dup returns an unfrozen copy, so I should be able to set instance variables on it. However, I get the following error even though the code is ractor-free:

test.rb:2:in 'Kernel#instance_variable_set': can't modify instance variables of a shareable Class (Ractor::IsolationError)

It works on 4.0 but fails on current master. Caused by #22291


Related issues 1 (0 open — 1 closed)

Related to Ruby - Bug #22291: Instance variables should be forbidden on Ractor-shareable objectsClosedActions

Updated by Earlopain (Earlopain _) 3 days ago Actions #1

  • Related to Bug #22291: Instance variables should be forbidden on Ractor-shareable objects added

Updated by Earlopain (Earlopain _) 3 days ago Actions #2

  • Description updated (diff)

Updated by luke-gru (Luke Gruber) 3 days ago Actions #3

  • Assignee set to ractor

Updated by Anonymous 1 day ago Actions #4

  • Status changed from Open to Closed

Applied in changeset git|bec5e51c85ded96969fd070ac5c3908d9f544723.


Fix Module/Class#dup of frozen object

This code should not raise an error:

@var = Class.new.freeze.dup # unfrozen copy
@var.instance_variable_set(:@test, 123)

It was raising Ractor::IsolationError because of a bug in rb_fields_tbl_copy.

This patch also fixes the following assertion failure in debug mode:

Module.new.freeze.singleton_class.instance_variable_set("@a", 1)

Now we get the proper behavior:

can't modify frozen Class: #<Class:#<Module:0x00000001094d9900>> (FrozenError)

Fixes [Bug #22378]

Actions

Also available in: PDF Atom