From 22f76db21567ef94304bc7dcda99b130e01182c7 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 12 Jun 2024 16:30:27 -0400 Subject: [PATCH] Catch 429s in more places --- gha-cache/src/api.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/gha-cache/src/api.rs b/gha-cache/src/api.rs index dd99b7b..3b26341 100644 --- a/gha-cache/src/api.rs +++ b/gha-cache/src/api.rs @@ -280,6 +280,18 @@ impl Api { self.circuit_breaker_429_tripped.load(Ordering::Relaxed) } + fn circuit_breaker_trip_on_429(&self, e: &Error) { + if let Error::ApiError { + status: reqwest::StatusCode::TOO_MANY_REQUESTS, + info: ref _info, + } = e + { + tracing::info!("Disabling GitHub Actions Cache due to 429: Too Many Requests"); + self.circuit_breaker_429_tripped + .store(true, Ordering::Relaxed); + } + } + /// Mutates the cache version/namespace. pub fn mutate_version(&mut self, data: &[u8]) { self.version_hasher.update(data); @@ -461,7 +473,8 @@ impl Api { .send() .await? .check_json() - .await; + .await + .inspect_err(|e| self.circuit_breaker_trip_on_429(e)); match res { Ok(entry) => Ok(Some(entry)), @@ -502,7 +515,8 @@ impl Api { .send() .await? .check_json() - .await?; + .await + .inspect_err(|e| self.circuit_breaker_trip_on_429(e))?; Ok(res) } @@ -526,7 +540,8 @@ impl Api { .send() .await? .check() - .await?; + .await + .inspect_err(|e| self.circuit_breaker_trip_on_429(e))?; Ok(()) }