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
53 changes: 29 additions & 24 deletions crates/uv-publish/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use itertools::Itertools;
use reqwest::header::AUTHORIZATION;
use reqwest::multipart::Part;
use reqwest::{Body, Response, StatusCode};
use reqwest_retry::RetryPolicy;
use reqwest_retry::policies::ExponentialBackoff;
use reqwest_retry::{RetryPolicy, Retryable, RetryableStrategy};
use rustc_hash::FxHashMap;
use serde::Deserialize;
use thiserror::Error;
Expand All @@ -28,7 +28,7 @@ use uv_auth::{Credentials, PyxTokenStore};
use uv_cache::{Cache, Refresh};
use uv_client::{
BaseClient, MetadataFormat, OwnedArchive, RegistryClientBuilder, RequestBuilder,
RetryParsingError, UvRetryableStrategy,
RetryParsingError, is_transient_network_error,
};
use uv_configuration::{KeyringProviderType, TrustedPublishing};
use uv_distribution_filename::{DistFilename, SourceDistExtension, SourceDistFilename};
Expand Down Expand Up @@ -484,31 +484,36 @@ pub async fn upload(
.map_err(|err| PublishError::PublishPrepare(group.file.clone(), Box::new(err)))?;

let result = request.send().await;
if UvRetryableStrategy.handle(&result) == Some(Retryable::Transient) {
let retry_decision = retry_policy.should_retry(start_time, n_past_retries);
if let reqwest_retry::RetryDecision::Retry { execute_after } = retry_decision {
let response = match result {
Ok(response) => {
reporter.on_upload_complete(idx);
let duration = execute_after
.duration_since(SystemTime::now())
.unwrap_or_else(|_| Duration::default());
warn_user!(
"Transient failure while handling response for {}; retrying after {}s...",
registry,
duration.as_secs()
);
tokio::time::sleep(duration).await;
n_past_retries += 1;
continue;
response
}
}
Err(err) => {
if is_transient_network_error(&err) {
let retry_decision = retry_policy.should_retry(start_time, n_past_retries);
if let reqwest_retry::RetryDecision::Retry { execute_after } = retry_decision {
let duration = execute_after
.duration_since(SystemTime::now())
.unwrap_or_else(|_| Duration::default());
warn_user!(
"Transient failure while handling response for {}; retrying after {}s...",
registry,
duration.as_secs()
);
tokio::time::sleep(duration).await;
n_past_retries += 1;
continue;
}
}

let response = result.map_err(|err| {
PublishError::PublishSend(
group.file.clone(),
registry.clone().into(),
PublishSendError::ReqwestMiddleware(err).into(),
)
})?;
return Err(PublishError::PublishSend(
group.file.clone(),
registry.clone().into(),
PublishSendError::ReqwestMiddleware(err).into(),
));
}
};

return match handle_response(registry, response).await {
Ok(()) => {
Expand Down
12 changes: 10 additions & 2 deletions crates/uv/src/commands/reporters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,13 @@ impl ProgressReporter {
return;
};

state.lock().unwrap().bars[&id].inc(bytes);
// Avoid panics due to reads on failed requests.
// https://github.com/astral-sh/uv/issues/17090
// TODO(konsti): Add a debug assert once https://github.com/seanmonstar/reqwest/issues/2884
// is fixed
if let Some(bar) = state.lock().unwrap().bars.get(&id) {
bar.inc(bytes);
}
}

fn on_request_complete(&self, direction: Direction, id: usize) {
Expand All @@ -322,7 +328,9 @@ impl ProgressReporter {
Direction::Download => "Downloaded",
Direction::Upload => "Uploaded",
Direction::Extract => "Extracted",
},
}
.bold()
.cyan(),
progress.message()
);
}
Expand Down
Loading