ruby-changes:49383
From: k0kubun <ko1@a...>
Date: Wed, 27 Dec 2017 22:33:05 +0900 (JST)
Subject: [ruby-changes:49383] k0kubun:r61498 (trunk): tool/downloader.rb: retry downloads
k0kubun 2017-12-27 22:32:59 +0900 (Wed, 27 Dec 2017) New Revision: 61498 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61498 Log: tool/downloader.rb: retry downloads because it's randomly failing on CI like https://ci.appveyor.com/project/ruby/ruby/build/1.0.6724 Actually I'm not sure whether the exception class is Errno::ECONNREFUSED or not. Please change the rescued exception to the correct one if it's wrong. I changed to log exception class too in this commit. Modified files: trunk/tool/downloader.rb Index: tool/downloader.rb =================================================================== --- tool/downloader.rb (revision 61497) +++ tool/downloader.rb (revision 61498) @@ -161,7 +161,9 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L161 $stdout.flush end begin - data = url.read(options.merge(http_options(file, since.nil? ? true : since))) + data = with_retry(3, Errno::ECONNREFUSED) do + url.read(options.merge(http_options(file, since.nil? ? true : since))) + end rescue OpenURI::HTTPError => http_error if http_error.message =~ /^304 / # 304 Not Modified if $VERBOSE @@ -207,7 +209,7 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L209 end return file.to_path rescue => e - raise "failed to download #{name}\n#{e.message}: #{url}" + raise "failed to download #{name}\n#{e.class}: #{e.message}: #{url}" end def self.under(dir, name) @@ -264,6 +266,21 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L266 end end end + + def self.with_retry(max_times, exception, &block) + times = 0 + begin + block.call + rescue exception => e + times += 1 + if times <= max_times + $stderr.puts "retrying #{e.class} (#{e.message}) after #{times ** 2} seconds..." + sleep(times ** 2) + retry + end + end + end + private_class_method :with_retry end Downloader.https = https.freeze -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/