Skip to content

Commit

Permalink
Place a bound on how many auth attempts will be tried
Browse files Browse the repository at this point in the history
  • Loading branch information
jklukas committed Jan 29, 2025
1 parent 357795d commit a91cc83
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/registry/http/http_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use http::Uri;

use hyper::{Body, Client};
use tokio::sync::Mutex;
use std::cmp::max;

use crate::registry::DockerAuthenticationHelper;

Expand Down Expand Up @@ -55,6 +56,8 @@ impl HttpCli {
{
let mut uri = uri.clone();
let mut attempt = 0;
let mut auth_attempt = 0;
let auth_retries = max(retries, 3);
let error = loop {
match run_single_request(
self.auth_info.clone(),
Expand All @@ -67,7 +70,7 @@ impl HttpCli {
{
Ok(o) => return Ok(o),
Err(err) => {
if attempt > retries {
if attempt > retries || auth_attempt > auth_retries {
break err;
}
attempt += 1;
Expand Down Expand Up @@ -108,7 +111,11 @@ impl HttpCli {
let mut ai = self.auth_info.lock().await;
*ai = Some(auth_info);
drop(ai);
// We need to retry the request after we have the new auth info, so this
// shouldn't count as an attempt, but we separately track auth attempts
// to prevent going into an infinite auth loop if access is denied.
attempt -= 1;
auth_attempt += 1;
continue;
}
}
Expand Down

0 comments on commit a91cc83

Please sign in to comment.