From 92c03be88847118bb64fb3ce035520b049247af5 Mon Sep 17 00:00:00 2001 From: k0kubun Date: Sat, 11 Aug 2018 04:22:14 +0000 Subject: [PATCH] tool/downloader.rb: retry on 502 and 503 error rubyci was failed by download 503 https://rubyci.org/logs/rubyci.s3.amazonaws.com/scw-9d6766/ruby-trunk/log/20180811T021706Z.fail.html.gz git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64282 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/downloader.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tool/downloader.rb b/tool/downloader.rb index c832b3ca9b..66de59066b 100644 --- a/tool/downloader.rb +++ b/tool/downloader.rb @@ -161,7 +161,7 @@ class Downloader $stdout.flush end begin - data = with_retry(3, [Errno::ETIMEDOUT, SocketError]) do + data = with_retry(3) do url.read(options.merge(http_options(file, since.nil? ? true : since))) end rescue OpenURI::HTTPError => http_error @@ -267,11 +267,12 @@ class Downloader end end - def self.with_retry(max_times, exceptions, &block) + def self.with_retry(max_times, &block) times = 0 begin block.call - rescue *exceptions => e + rescue Errno::ETIMEDOUT, SocketError, OpenURI::HTTPError => e + raise if e.is_a?(OpenURI::HTTPError) && e.message !~ /^50[23] / # retry only 502, 503 for http error times += 1 if times <= max_times $stderr.puts "retrying #{e.class} (#{e.message}) after #{times ** 2} seconds..."