From ff6c540adb5b60b0fd75152434fa67b1fa3d26b7 Mon Sep 17 00:00:00 2001 From: k0kubun Date: Wed, 27 Dec 2017 13:32:59 +0000 Subject: 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61498 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/downloader.rb | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tool/downloader.rb') diff --git a/tool/downloader.rb b/tool/downloader.rb index 335fe97762..c6f6c4701c 100644 --- a/tool/downloader.rb +++ b/tool/downloader.rb @@ -161,7 +161,9 @@ class Downloader $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 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 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 -- cgit v1.2.1