Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retries to some online audit checks #16113

Merged
merged 1 commit into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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

Check warning on line 154 in Library/Homebrew/resource_auditor.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource_auditor.rb#L153-L154

Added lines #L153 - L154 were not covered by tests
remote_exists = Utils::Git.remote_exists?(url)
attempts += 1

Check warning on line 156 in Library/Homebrew/resource_auditor.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/resource_auditor.rb#L156

Added line #L156 was not covered by tests
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 @@
end

details = T.let(nil, T.nilable(T::Hash[Symbol, T.untyped]))
attempts = 0

Check warning on line 301 in Library/Homebrew/utils/curl.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/curl.rb#L301

Added line #L301 was not covered by tests
user_agents.each do |user_agent|
details =
curl_http_content_headers_and_checksum(
loop do
details = curl_http_content_headers_and_checksum(

Check warning on line 304 in Library/Homebrew/utils/curl.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/curl.rb#L303-L304

Added lines #L303 - L304 were not covered by tests
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

Check warning on line 316 in Library/Homebrew/utils/curl.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/utils/curl.rb#L316

Added line #L316 was not covered by tests
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 @@
{
url: url,
final_url: final_url,
exit_status: status.exitstatus,
status_code: status_code,
headers: headers,
etag: etag,
Expand Down