Project

General

Profile

Actions

Bug #15599

open

Mixing autoload and require causes deadlock and incomplete definition.

Added by akr (Akira Tanaka) almost 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 2.7.0dev (2019-02-11 trunk 67049) [x86_64-linux]
[ruby-core:91519]

Description

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 `<main>'
base.rb:6:in `join': No live threads left. Deadlock? (fatal)
3 threads, 3 sleeps current:0x000055cc6943fde0 main thread:0x000055cc6935f4b0
* #<Thread:0x000055cc6938f190 sleep_forever>
   rb_thread_t:0x000055cc6935f4b0 native:0x00007f58d256eb40 int:0
   base.rb:6:in `join'
   base.rb:6:in `<main>'
* #<Thread:0x000055cc6968cfc8@base.rb:3 sleep_forever>
   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 <main>'
* #<Thread:0x000055cc6968ccd0@base.rb:4 sleep_forever>
   rb_thread_t:0x000055cc6943fde0 native:0x00007f58ce5b1700 int:0
   /tmp/a/a.rb:1:in `<top (required)>'
   /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 <main>'
% ruby base.rb
[:a1]
% ruby base.rb
[]

The last run which prints [] means incomplete definition of A which a1 method is not defined.


Related issues 1 (1 open0 closed)

Related to Ruby master - Bug #15598: Deadlock on mutual reference of autoloaded constantsOpenActions
Actions #1

Updated by akr (Akira Tanaka) almost 6 years ago

  • Related to Bug #15598: Deadlock on mutual reference of autoloaded constants added
Actions

Also available in: Atom PDF

Like0
Like0