ruby-changes:69490
From: Nobuyoshi <ko1@a...>
Date: Thu, 28 Oct 2021 17:55:31 +0900 (JST)
Subject: [ruby-changes:69490] e76e1d3ce4 (master): Downloader: retry when RFC 2616 noncompliant dates [ci skip]
https://git.ruby-lang.org/ruby.git/commit/?id=e76e1d3ce4 From e76e1d3ce4bf65b3c7f56e09dd5f51b79538df18 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 28 Oct 2021 17:42:36 +0900 Subject: Downloader: retry when RFC 2616 noncompliant dates [ci skip] zlib.net rarely returns the current time in RFC 2616 noncompliant format in the response header, and the checksum does not match in that case (maybe creating the tarball on the fly?). --- tool/downloader.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tool/downloader.rb b/tool/downloader.rb index e9ea00c4c4e..d3a9f756375 100644 --- a/tool/downloader.rb +++ b/tool/downloader.rb @@ -211,9 +211,15 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L211 $stdout.print "downloading #{name} ... " $stdout.flush end + mtime = nil + options = options.merge(http_options(file, since.nil? ? true : since)) begin data = with_retry(10) do - url.read(options.merge(http_options(file, since.nil? ? true : since))) + data = url.read(options) + if mtime = data.meta["last-modified"] + mtime = Time.httpdate(mtime) + end + data end rescue OpenURI::HTTPError => http_error if http_error.message =~ /^304 / # 304 Not Modified @@ -237,16 +243,13 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L243 end raise end - mtime = nil dest = (cache_save && cache && !cache.exist? ? cache : file) dest.parent.mkpath dest.open("wb", 0600) do |f| f.write(data) f.chmod(mode_for(data)) - mtime = data.meta["last-modified"] end if mtime - mtime = httpdate(mtime) dest.utime(mtime, mtime) end if $VERBOSE @@ -328,7 +331,7 @@ class Downloader https://github.com/ruby/ruby/blob/trunk/tool/downloader.rb#L331 times = 0 begin block.call - rescue Errno::ETIMEDOUT, SocketError, OpenURI::HTTPError, Net::ReadTimeout, Net::OpenTimeout => e + rescue Errno::ETIMEDOUT, SocketError, OpenURI::HTTPError, Net::ReadTimeout, Net::OpenTimeout, ArgumentError => e raise if e.is_a?(OpenURI::HTTPError) && e.message !~ /^50[023] / # retry only 500, 502, 503 for http error times += 1 if times <= max_times -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/