From: "mame (Yusuke Endoh) via ruby-core" Date: 2026-10-09T09:25:22+00:00 Subject: [ruby-core:127027] [Ruby Bug#15599] Mixing autoload and require causes deadlock and incomplete definition. Issue #15599 has been updated by mame (Yusuke Endoh). Status changed from Closed to Open This issue is not fixed. The M:N thread scheduler seems to have only changed the timing. Adding `sleep` makes each result deterministic (confirmed on 3.3.8, 3.4.4, 4.0.2, and master). i) shows `[:a1]` ``` $ cat a.rb class A def a1() end end $ cat base.rb autoload :A, './a' t1 = Thread.new { p A.instance_methods(false) } t2 = Thread.new { sleep 0.1; require './a' } t1.join t2.join $ ruby base.rb [:a1] ``` ii) shows `[]` ``` $ cat a.rb class A sleep 0.2 def a1() end end $ cat base.rb autoload :A, './a' t1 = Thread.new { sleep 0.1; p A.instance_methods(false) } t2 = Thread.new { require './a' } t1.join t2.join $ ruby base.rb [] ``` iii) deadlocks ``` $ cat a.rb sleep 0.2 class A def a1() end end $ cat base.rb autoload :A, './a' t1 = Thread.new { sleep 0.1; p A.instance_methods(false) } t2 = Thread.new { require './a' } t1.join t2.join $ ruby base.rb base.rb:6:in 'Thread#join': No live threads left. Deadlock? (fatal) ``` The only difference among these is where `sleep` is inserted. Let me reopen this. ---------------------------------------- Bug #15599: Mixing autoload and require causes deadlock and incomplete definition. https://bugs.ruby-lang.org/issues/15599#change-119423 * Author: akr (Akira Tanaka) * Status: Open * ruby -v: ruby 2.7.0dev (2019-02-11 trunk 67049) [x86_64-linux] * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- I found that mixing autoload and require causes deadlock and incomplete definition. ``` % cat a.rb class A def a1() end end % cat base.rb autoload :A, './a' t1 = Thread.new { p A.instance_methods(false) } t2 = Thread.new { require './a' } t1.join t2.join % ruby base.rb Traceback (most recent call last): 1: from base.rb:6:in `
' base.rb:6:in `join': No live threads left. Deadlock? (fatal) 3 threads, 3 sleeps current:0x000055cc6943fde0 main thread:0x000055cc6935f4b0 * # rb_thread_t:0x000055cc6935f4b0 native:0x00007f58d256eb40 int:0 base.rb:6:in `join' base.rb:6:in `
' * # rb_thread_t:0x000055cc69736180 native:0x00007f58ce7b3700 int:0 mutex:0x000055cc6943fde0 cond:1 depended by: tb_thread_id:0x000055cc6935f4b0 /home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require' /home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require' base.rb:3:in `block in
' * # rb_thread_t:0x000055cc6943fde0 native:0x00007f58ce5b1700 int:0 /tmp/a/a.rb:1:in `' /home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require' /home/akr/ruby/o0/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:54:in `require' base.rb:4:in `block in
' % ruby base.rb [:a1] % ruby base.rb [] ``` The last run which prints [] means incomplete definition of A which a1 method is not defined. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/