Bug #21812
openKernel#sleep without arguments returns immediately when subprocess exits in another thread (regression in Ruby 4.0)
Description
Description
In Ruby 4.0.0, Kernel#sleep without arguments returns 0 immediately when a subprocess (spawned via backticks in another thread) exits. This is a regression from Ruby 3.4.8 where sleep blocks indefinitely as expected.
Note: sleep(N) with an argument is not affected.
Steps to reproduce
# test_sleep.rb
Thread.new do
sleep 0.3
`echo hello` # Spawns subprocess
puts "Subprocess exited"
end
puts "Main thread sleeping..."
result = sleep # Should block forever
puts "sleep returned: #{result.inspect}"
Run with:
$ ruby test_sleep.rb
Actual result (Ruby 4.0.0):
Main thread sleeping...
Subprocess exited
sleep returned: 0
The program exits immediately after the subprocess completes.
Expected result (Ruby 3.4.8 behavior):
Main thread sleeping...
Subprocess exited
(process blocks indefinitely until interrupted by signal)
The program should block forever until explicitly interrupted by SIGINT/SIGTERM.
Updated by mame (Yusuke Endoh) about 6 hours ago
- Status changed from Open to Assigned
- Assignee set to luke-gru (Luke Gruber)
Thanks for the nice catch.
git bisect points to 8d8159e7d87e4fd1594ce2fad3d2653e47fb1026. The changes in that commit seem relevant to this issue.
@luke-gru (Luke Gruber) Could you take a look?