8000 Fix by ianoc · Pull Request #419 · bazeltools/rules_minidock_tools · GitHub
[go: up one dir, main page]

Skip to content
Merged

Fix #419

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
7 changes: 4 additions & 3 deletions src/registry/http/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl BlobStore for super::HttpRegistry {

let mut r = self
.http_client
.request_simple(&uri, http::Method::HEAD, 3)
.request_simple(&uri, http::Method::HEAD, 3, false)
.await?;

if r.status() == StatusCode::NOT_FOUND {
Expand Down Expand Up @@ -54,7 +54,7 @@ impl BlobStore for super::HttpRegistry {
let uri = self.repository_uri_from_path(format!("/blobs/{}", digest))?;
let mut response = self
.http_client
.request_simple(&uri, http::Method::GET, 3)
.request_simple(&uri, http::Method::GET, 3, false)
.await?;

if response.status() != StatusCode::OK {
Expand Down Expand Up @@ -123,7 +123,7 @@ impl BlobStore for super::HttpRegistry {

let mut r = self
.http_client
.request_simple(&post_target_uri, http::Method::POST, 0)
.request_simple(&post_target_uri, http::Method::POST, 0, false)
.await?;

if r.status() != StatusCode::ACCEPTED {
Expand Down Expand Up @@ -212,6 +212,7 @@ impl BlobStore for super::HttpRegistry {
.map_err(|e| e.into())
},
0,
false,
)
.await?;

Expand Down
1 change: 1 addition & 0 deletions src/registry/http/copy_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl CopyOperations for super::HttpRegistry {
.map_err(|e| e.into())
},
3,
false,
)
.await?;

Expand Down
41 changes: 26 additions & 15 deletions src/registry/http/http_cli/mod.rs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ impl HttpCli {
uri: &Uri,
method: http::Method,
retries: usize,
ignore_auth_fail: bool,
) -> Result<Response<Body>, anyhow::Error> {
self.request(
uri,
method,
|method, c| async { c.method(method).body(Body::from("")).map_err(|e| e.into()) },
retries,
ignore_auth_fail
)
.await
}
Expand All @@ -45,6 +47,9 @@ impl HttpCli {
context: B,
complete_request: F,
retries: usize,
// Sometimes when we fetch the root of a repository, we might fail with an auth error
// not then the rest of the flow/targeted paths are fine.
ignore_auth_fail: bool,
) -> Result<Response<Body>, anyhow::Error>
where
F: Fn(B, http::request::Builder) -> Fut,
Expand All @@ -53,9 +58,7 @@ impl HttpCli {
{
let mut uri = uri.clone();
let mut attempt = 0;
let mut last_error: Option<RequestFailType> = None;
while attempt < retries + 1 {
attempt += 1;
let error = loop {
match run_single_request(
self.auth_info.clone(),
&uri,
Expand All @@ -67,9 +70,13 @@ impl HttpCli {
{
Ok(o) => return Ok(o),
Err(err) => {
last_error = Some(err);
if attempt >= retries {
break err;
}
attempt += 1;

// Unwrap safe because we set the line right before this.
match &last_error.as_ref().unwrap() {
match err {
RequestFailType::Redirection(new_url) => {
let new_uri = new_url.parse::<Uri>().with_context(|| {
format!("Failed to parse new url {:?}", new_url)
Expand All @@ -91,11 +98,14 @@ impl HttpCli {
continue;
}
RequestFailType::ConnectError(_) => continue,
RequestFailType::HyperError(_) => break, // terminal.
RequestFailType::AnyhowError(_) => break, // terminal.
RequestFailType::AuthFailure(auth_fail) => {
RequestFailType::HyperError(_) => break err, // terminal.
RequestFailType::AnyhowError(_) => break err, // terminal.
RequestFailType::AuthFailure(resp, auth_fail) => {
if ignore_auth_fail {
return Ok(resp);
}
let auth_info = authentication_flow::authenticate_request(
auth_fail,
&auth_fail,
&self.inner_client,
self.docker_authorization_helpers.clone(),
)
Expand All @@ -109,11 +119,12 @@ impl HttpCli {
}
}
}
}
match last_error {
None => anyhow::bail!("We failed in trying to issue http requests, but we have no last error. Unexpected state. Attempting to query: {:?}", uri),
Some(ex) =>
Err(ex).with_context(|| format!("Exhausted attempts, or ran into terminal error issuing http requests to URI: {:?}", uri))
}
};
Err(error).with_context(|| {
format!(
"Exhausted attempts, or ran into terminal error issuing http requests to URI: {:?}",
uri
)
})
}
}
6 changes: 3 additions & 3 deletions src/registry/http/http_cli/private_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ pub enum RequestFailType {
HyperError(hyper::Error),
#[error("Internal error: '{0:?}'")]
AnyhowError(anyhow::Error),
#[error("Auth failed: '{0}'")]
AuthFailure(BearerConfig),
#[error("Auth failed: '{1}'")]
AuthFailure(Response<Body>, BearerConfig),
#[error("Got a redirection code: '{0}'")]
Redirection(String),
}
Expand Down Expand Up @@ -163,7 +163,7 @@ where
auth_header
)
})?;
return Err(RequestFailType::AuthFailure(b));
return Err(RequestFailType::AuthFailure(r, b));
}
}
if r.status().is_redirection() {
Expand Down
3 changes: 2 additions & 1 deletion src/registry/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl super::RegistryCore for HttpRegistry {
.map_err(|e| e.into())
},
0,
false,
)
.await;

Expand Down Expand Up @@ -134,7 +135,7 @@ impl HttpRegistry {

let req_future = reg
.http_client
.request_simple(&req_uri, http::Method::HEAD, 3);
.request_simple(&req_uri, http::Method::HEAD, 3, true);

let mut resp = match timeout(Duration::from_millis(20000), req_future).await {
Err(_) => bail!(
Expand Down
1 change: 1 addition & 0 deletions src/registry/http/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub(super) async fn request_path_in_repository_as_string(
.map_err(|e| e.into())
},
3,
false
)
.await?;

Expand Down
0