async: `system` hangs if file does not exist

If you run system inside Async with a non-existent executable on Linux with Ruby 3.3 it hangs. This behavior is confirmed in 2.17.0 and 2.18.0 (I didn’t check any earlier than that).

This synchronous code works:

puts "Running on: #{RbConfig::CONFIG['host_os']}"
res = system 'echo', 'hello'
puts "Result 1: #{res}"
res = system 'does-not-exist', 'hello'
puts "Result 2: #{res}"

And outputs:

Running on: linux
hello
Result 1: true
Result 2:

But this code does not:

require 'async'

Async do
  puts "Running on: #{RbConfig::CONFIG['host_os']}"
  res = system 'echo', 'hello'
  puts "Result 1: #{res}"
  res = system 'does-not-exist', 'hello'
  puts "Result 2: #{res}"
end

This hangs on the second system call. This was discovered after a deep dive of why Minitest assert_equal was hanging. It turns out, Minitest uses diff on the system when reporting an assert_equal failure, but first checks for gdiff which we don’t have, ref: https://github.com/minitest/minitest/blob/e4417c5b13ab917a60c218700041152136bc07c8/lib/minitest/assertions.rb#L33. So we have to Minitest::Assertions.diff = 'diff' to get Async-based tests to not break here.

(sorry if this is already reported, I could not find an issue)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 21 (18 by maintainers)

Commits related to this issue

Most upvoted comments

Can you please try io-event v1.7.5 - this issue should be fixed.

Thanks for reporting the issue!

Yes, it is fixed now. Thanks a lot for your work!

I’m still seeing this problem, but it seems to apply to all system calls instead of only illegal commands as originally described here. It happens after calling system twice within a single Async task.

RUBY_VERSION
=> "3.3.6"

IO::Event::VERSION
=> "1.7.4"

IO::Event::Selector.default
=> IO::Event::Selector::EPoll

Async { 2.times { system "echo #{_1}" } }
0
1
^C # Hangs here with the second spawned process in Zombie state

Async { 2.times { system "fakeecho #{_1}" } }
=> #<Async::Task:0x0000000000028334>
# Calling illegal commands no longer triggers a hang

This only happens when EPoll selector is used, and not with io_uring.

I’ve released io-event v1.7.4 which appears to fix this issue. Please let me know if you are still having issues.

Okay, I believe I’ve found the root cause, a race condition in the process wait code.

Nice find. I didn’t know about this! haha.

image

I’ll investigate the issue today.