Project

General

Profile

Actions

Bug #21926

open

Thread#value on popen3 wait thread hangs in finalizer

Bug #21926: Thread#value on popen3 wait thread hangs in finalizer

Added by stevecrozz (Stephen Crosby) about 17 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:124887]

Description

Calling Thread#value on an Open3.popen3 wait thread from a finalizer completes in Ruby 3.2 but hangs in Ruby 3.3+. See repro.rb below. When the Ruby process hangs in these conditions, it no longer responds to signals and it seems to be unable to run any other threads.

This affects the schmooze gem (and potentially other code using Open3.popen3 with finalizers), causing test suites to hang intermittently.

# repro.rb
require 'open3'

class ProcessWrapper
  def initialize
    @stdin, @stdout, @stderr, @wait_thread = Open3.popen3("cat")
    ObjectSpace.define_finalizer(self, self.class.make_finalizer(@stdin, @stdout, @stderr, @wait_thread))
  end
                                                       
  def self.make_finalizer(stdin, stdout, stderr, wait_thread)
    proc do
      stdin.close rescue nil
      stdout.close rescue nil
      stderr.close rescue nil
      wait_thread.value  # Hangs here in Ruby 3.3+
    end
  end
end
                  
100.times { ProcessWrapper.new } 
GC.stress = true
1000.times { Object.new } 
puts "done"

Environment

  • Linux x86_64
  • Tested on Ruby 3.2.7, 3.3.7, 3.4.8

No data to display

Actions

Also available in: PDF Atom