Skip to content

Commit

Permalink
Merge pull request #16162 from Bo98/system_command-stderr-fix
Browse files Browse the repository at this point in the history
system_command: fix potential issue of stderr not being read
  • Loading branch information
MikeMcQuaid authored Oct 30, 2023
2 parents c02a45f + dd9359d commit 53107a5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions Library/Homebrew/system_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def each_line_from(sources, &_block)

pending_interrupt = T.let(false, T::Boolean)

until pending_interrupt
until pending_interrupt || sources.empty?
readable_sources = T.let([], T::Array[IO])
begin
Thread.handle_interrupt(ProcessTerminatedInterrupt => :on_blocking) do
Expand All @@ -302,17 +302,16 @@ def each_line_from(sources, &_block)
pending_interrupt = true
end

break if readable_sources.none? do |source|
readable_sources.each do |source|
loop do
line = source.readline_nonblock || ""
yield(sources.fetch(source), line)
end
rescue EOFError
source.close_read
sources.delete(source)
sources.any?
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

Expand Down

0 comments on commit 53107a5

Please sign in to comment.