Project

General

Profile

Actions

Bug #21719

open

Thread deadlock with explicit require of a base clase in Linux Ruby 3.4

Bug #21719: Thread deadlock with explicit require of a base clase in Linux Ruby 3.4

Added by jcuello@fu.do (Juan Manuel Cuello) about 5 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux]
[ruby-core:123951]

Description

I originally reported the issue in Zeitwerk, but we then figured out that it seems to be related to Ruby.

Basically, I'm having a threads deadlock when using requires with autoloadable classes:

# jobs/base.rb
#
module Jobs
 class Base
 end
end

# jobs/a.rb
#
require './jobs/base'

module Jobs
  class A < Base
    def perform
      puts self.class.name
    end
  end
end

# jobs/b.rb
#
module Jobs
  class B < Base
    def perform
      puts self.class.name
    end
  end
end

# start.rb
#
module Jobs
  autoload :Base, './jobs/base'
  autoload :A, './jobs/a'
  autoload :B, './jobs/b'
end

a = Thread.new { Jobs::A.new.perform }
b = Thread.new { Jobs::B.new.perform }

a.join
b.join
ruby --version && ruby start.rb
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux]
start.rb:12:in 'Thread#join': No live threads left. Deadlock? (fatal)
3 threads, 3 sleeps current:0x00005ca30dfbc500 main thread:0x00005ca30dd30330
* #<Thread:0x000076b1a7d6a658 sleep_forever>
   rb_thread_t:0x00005ca30dd30330 native:0x000076b1a81b87c0 int:0
   
* #<Thread:0x000076b1a7d2e928 start.rb:9 sleep_forever>
   rb_thread_t:0x00005ca30dfbc500 native:0x000076b18c74d6c0 int:0
    depended by: tb_thread_id:0x00005ca30dd30330
   
* #<Thread:0x000076b1a7d2e3b0 start.rb:10 sleep_forever>
   rb_thread_t:0x00005ca30dfb0fd0 native:0x000076b18c54b6c0 int:0 mutex:0x00005ca30dfe2b60 cond:1
   

        from start.rb:12:in '<main>'

Note the require './jobs/base' in jobs/a.rb. If I remove it, everything works. The same happens if I add the same explicit require in jobs/b.rb.

It seems to have been fixed in ruby 3.4 in ea2af5782df63266577ba08a4ef4c30b6d63e564, but not apparent in Linux (which is my case) until 6fbc32b5d0da31535cccc0eca1853273313a0b52

I'm not familiar with the ruby codebase, so It's not clear to me why the change to prism fixed the threads issue and why it didn't have impact in Linux until the other fix, but bisecting the source code and running each revision against the code above, that is what I came to.

I can create a PR to backport the Linux fix to ruby_3_4 branch, as in master everything is working as expected.

No data to display

Actions

Also available in: PDF Atom