Skip to content

Commit 0d81177

Browse files
luke-gruko1
authored andcommitted
Fix calls to require_internal in multi-ractor mode
After a ractor is started (multi-ractor mode), any calls to require_internal will hang the process due to deadlock. For example, loading a new encoding will deadlock after a ractor starts. Fixes [Bug #19562]
1 parent 38af38e commit 0d81177

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ractor.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,13 +2341,12 @@ ractor_check_blocking(rb_ractor_t *cr, unsigned int remained_thread_cnt, const c
23412341
cr->threads.cnt == cr->threads.blocking_cnt + 1) {
23422342
// change ractor status: running -> blocking
23432343
rb_vm_t *vm = GET_VM();
2344-
ASSERT_vm_unlocking();
23452344

2346-
RB_VM_LOCK();
2345+
RB_VM_LOCK_ENTER();
23472346
{
23482347
rb_vm_ractor_blocking_cnt_inc(vm, cr, file, line);
23492348
}
2350-
RB_VM_UNLOCK();
2349+
RB_VM_LOCK_LEAVE();
23512350
}
23522351
}
23532352

test/ruby/test_encoding.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,14 @@ def test_nonascii_library_path
126126
end
127127
end;
128128
end
129+
130+
def test_ractor_load_encoding
131+
assert_ractor("#{<<~"begin;"}\n#{<<~'end;'}")
132+
begin;
133+
Ractor.new{}.take
134+
$-w = nil
135+
Encoding.default_external = Encoding::ISO8859_2
136+
assert "[Bug #19562]"
137+
end;
138+
end
129139
end

0 commit comments

Comments
 (0)