From 6b63660817b8f66d890692b1cfb24aa86e099f16 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:39:58 +0800 Subject: [PATCH] attestation: retry on `InvalidAttestationError` instead --- Library/Homebrew/attestation.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/attestation.rb b/Library/Homebrew/attestation.rb index 3e19d100bc..d456651b13 100644 --- a/Library/Homebrew/attestation.rb +++ b/Library/Homebrew/attestation.rb @@ -179,6 +179,8 @@ module Homebrew attestation end + ATTESTATION_MAX_RETRIES = 5 + # Verifies the given bottle against a cryptographic attestation of build provenance # from homebrew-core's CI, falling back on a "backfill" attestation for older bottles. # @@ -246,12 +248,15 @@ module Homebrew end backfill_attestation - rescue InvalidAttestationError => e - raise if ENV["HOMEBREW_GITHUB_ACTIONS"].blank? + rescue InvalidAttestationError + @attestation_retry_count ||= T.let(Hash.new(0), T.nilable(T::Hash[Bottle, Integer])) + raise if @attestation_retry_count[bottle] >= ATTESTATION_MAX_RETRIES - opoo "Attestation verification failed (please verify that this is not a network error before rebottling): #{e}" - - {} + sleep_time = 3 ** @attestation_retry_count[bottle] + opoo "Failed to verify attestation. Retrying in #{sleep_time}..." + sleep sleep_time + @attestation_retry_count[bottle] += 1 + retry end end end