From 0d81177c2013b0a596eb4caebe0bcca557144139 Mon Sep 17 00:00:00 2001 From: lukeg Date: Tue, 4 Apr 2023 16:24:59 -0400 Subject: [PATCH] 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] --- ractor.c | 5 ++--- test/ruby/test_encoding.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/ractor.c b/ractor.c index 2dfd56d068..737aa6f24a 100644 --- a/ractor.c +++ b/ractor.c @@ -2341,13 +2341,12 @@ ractor_check_blocking(rb_ractor_t *cr, unsigned int remained_thread_cnt, const c cr->threads.cnt == cr->threads.blocking_cnt + 1) { // change ractor status: running -> blocking rb_vm_t *vm = GET_VM(); - ASSERT_vm_unlocking(); - RB_VM_LOCK(); + RB_VM_LOCK_ENTER(); { rb_vm_ractor_blocking_cnt_inc(vm, cr, file, line); } - RB_VM_UNLOCK(); + RB_VM_LOCK_LEAVE(); } } diff --git a/test/ruby/test_encoding.rb b/test/ruby/test_encoding.rb index f2c609a4cd..388b94df39 100644 --- a/test/ruby/test_encoding.rb +++ b/test/ruby/test_encoding.rb @@ -126,4 +126,14 @@ class TestEncoding < Test::Unit::TestCase end end; end + + def test_ractor_load_encoding + assert_ractor("#{<<~"begin;"}\n#{<<~'end;'}") + begin; + Ractor.new{}.take + $-w = nil + Encoding.default_external = Encoding::ISO8859_2 + assert "[Bug #19562]" + end; + end end