8000 Add retries on server error for blob uploads by jklukas · Pull Request #565 · bazeltools/rules_minidock_tools · GitHub
[go: up one dir, main page]

Skip to content
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
4 changes: 2 additions & 2 deletions src/registry/http/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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, 3)
.await
.with_context(|| {
format!(
Expand Down Expand Up @@ -219,7 +219,7 @@ impl BlobStore for super::HttpRegistry {
.body(body)
.map_err(|e| e.into())
},
0,
3,
)
.await
.context("Performing upload bytes operation")?;
Expand Down
1 change: 1 addition & 0 deletions src/registry/http/http_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl HttpCli {
continue;
}
RequestFailType::ConnectError(_) => continue,
RequestFailType::ServerError(_, _) => continue, // Retry server errors
RequestFailType::HyperError(_) => break err, // terminal.
RequestFailType::AnyhowError(_) => break err, // terminal.
RequestFailType::AuthFailure(_, auth_fail) => {
Expand Down
9 changes: 9 additions & 0 deletions src/registry/http/http_cli/private_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ pub enum RequestFailType {
AuthFailure(Response<Body>, BearerConfig),
#[error("Got a redirection code: '{0}'")]
Redirection(String),
#[error("Server error (retryable): status {0}")]
ServerError(StatusCode, Response<Body>),
}
impl From<anyhow::Error> for RequestFailType {
fn from(e: anyhow::Error) -> Self {
Expand Down Expand Up @@ -174,6 +176,13 @@ where
return Err(RequestFailType::Redirection(location_str.to_string()));
}
}
// Handle server errors (502, 503, 504) as retryable conditions
if r.status() == StatusCode::BAD_GATEWAY
|| r.status() == StatusCode::SERVICE_UNAVAILABLE
|| r.status() == StatusCode::GATEWAY_TIMEOUT
{
return Err(RequestFailType::ServerError(r.status(), r));
}
r
}
};
Expand Down
0