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
- Fix issue with async and minitest, see https://github.com/socketry/async/issues/351 — committed to cretz/temporal-sdk-ruby by cretz 2 years ago
- Add test for non-existant executable. See <https://github.com/socketry/async/issues/351> for context. — committed to socketry/async by ioquatix 2 years ago
Can you please try
io-eventv1.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
systemcalls instead of only illegal commands as originally described here. It happens after callingsystemtwice within a single Async task.This only happens when EPoll selector is used, and not with io_uring.
I’ve released
io-eventv1.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.
I’ll investigate the issue today.