Skip to content

Commit

Permalink
Merge pull request #16113 from Bo98/audit-retry
Browse files Browse the repository at this point in the history
Add retries to some online audit checks
  • Loading branch information
Bo98 committed Oct 14, 2023
2 parents fbe50bf + e80bb70 commit c0c8a4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Library/Homebrew/resource_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,13 @@ def audit_urls
problem http_content_problem
end
elsif strategy <= GitDownloadStrategy
problem "The URL #{url} is not a valid git URL" unless Utils::Git.remote_exists? url
attempts = 0
remote_exists = T.let(false, T::Boolean)
while !remote_exists && attempts < Homebrew::EnvConfig.curl_retries.to_i
remote_exists = Utils::Git.remote_exists?(url)
attempts += 1
end
problem "The URL #{url} is not a valid git URL" unless remote_exists
elsif strategy <= SubversionDownloadStrategy
next unless DevelopmentTools.subversion_handles_most_https_certificates?
next unless Utils::Svn.available?
Expand Down
14 changes: 12 additions & 2 deletions Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,16 +298,25 @@ def curl_check_http_content(url, url_type, specs: {}, user_agents: [:default], r
end

details = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped]))
attempts = 0
user_agents.each do |user_agent|
details =
curl_http_content_headers_and_checksum(
loop do
details = curl_http_content_headers_and_checksum(
url,
specs: specs,
hash_needed: hash_needed,
use_homebrew_curl: use_homebrew_curl,
user_agent: user_agent,
referer: referer,
)

# Retry on network issues
break if details[:exit_status] != 52 && details[:exit_status] != 56

attempts += 1
break if attempts >= Homebrew::EnvConfig.curl_retries.to_i
end

break if http_status_ok?(details[:status_code])
end

Expand Down Expand Up @@ -453,6 +462,7 @@ def curl_http_content_headers_and_checksum(
{
url: url,
final_url: final_url,
exit_status: status.exitstatus,
status_code: status_code,
headers: headers,
etag: etag,
Expand Down

0 comments on commit c0c8a4d

Please sign in to comment.