From 9e089a7d1299db498f121e17b5f68f0cc3c40953 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 21 Apr 2017 07:11:40 +0200 Subject: [PATCH 1/2] Fix `IO#select` blocking. --- .../Homebrew/cask/lib/hbc/system_command.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index c14079bc8b..65e54b4479 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -91,18 +91,32 @@ module Hbc end def each_line_from(sources) + tries = 3 + loop do - readable_sources = IO.select(sources)[0] - readable_sources.delete_if(&:eof?).first(1).each do |source| + selected_sources = IO.select(sources, [], [], 1) + + if selected_sources.nil? + next unless (tries -= 1).zero? + odebug "IO#select failed, skipping line." + break + end + + readable_sources = selected_sources[0].delete_if(&:eof?) + + readable_sources.each do |source| type = (source == sources[0] ? :stdout : :stderr) + begin yield(type, source.readline_nonblock || "") rescue IO::WaitReadable, EOFError next end end + break if readable_sources.empty? end + sources.each(&:close_read) end From cc634b2d50cc0e8c1e8a38196f4bcdad4e0a69b6 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 21 Apr 2017 14:12:16 +0200 Subject: [PATCH 2/2] Set timeout to 10 seconds instead of retrying. --- Library/Homebrew/cask/lib/hbc/system_command.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index 65e54b4479..f1ec340256 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -91,16 +91,10 @@ module Hbc end def each_line_from(sources) - tries = 3 - loop do - selected_sources = IO.select(sources, [], [], 1) + selected_sources = IO.select(sources, [], [], 10) - if selected_sources.nil? - next unless (tries -= 1).zero? - odebug "IO#select failed, skipping line." - break - end + break if selected_sources.nil? readable_sources = selected_sources[0].delete_if(&:eof?)