system_command: fix potential issue of stderr not being read

This commit is contained in:
Bo Anderson 2023-10-29 03:43:52 +00:00
parent 700c7dea3f
commit dd9359df12
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65

View File

@ -291,7 +291,7 @@ class SystemCommand
pending_interrupt = T.let(false, T::Boolean) pending_interrupt = T.let(false, T::Boolean)
until pending_interrupt until pending_interrupt || sources.empty?
readable_sources = T.let([], T::Array[IO]) readable_sources = T.let([], T::Array[IO])
begin begin
Thread.handle_interrupt(ProcessTerminatedInterrupt => :on_blocking) do Thread.handle_interrupt(ProcessTerminatedInterrupt => :on_blocking) do
@ -302,7 +302,7 @@ class SystemCommand
pending_interrupt = true pending_interrupt = true
end end
break if readable_sources.none? do |source| readable_sources.each do |source|
loop do loop do
line = source.readline_nonblock || "" line = source.readline_nonblock || ""
yield(sources.fetch(source), line) yield(sources.fetch(source), line)
@ -310,9 +310,8 @@ class SystemCommand
rescue EOFError rescue EOFError
source.close_read source.close_read
sources.delete(source) sources.delete(source)
sources.any?
rescue IO::WaitReadable rescue IO::WaitReadable
true # We've got all the data that was ready, but the other end of the stream isn't finished yet
end end
end end