Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 2 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async-compression = { version = "0.4.12", features = [
"zstd",
] }
async-trait = { version = "0.1.82" }
async_http_range_reader = { version = "0.10.0", package = "astral_async_http_range_reader" }
async_http_range_reader = { version = "0.11.0", package = "astral_async_http_range_reader" }
async_zip = { version = "0.0.17", package = "astral_async_zip", features = [
"bzip2",
"deflate",
Expand Down
56 changes: 48 additions & 8 deletions crates/uv-client/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use reqwest::Response;
use serde::Deserialize;
use tracing::warn;

use crate::middleware::OfflineError;
use crate::{FlatIndexError, html};
use uv_cache::Error as CacheError;
use uv_distribution_filename::{WheelFilename, WheelFilenameError};
use uv_distribution_types::IndexUrl;
use uv_normalize::PackageName;
use uv_redacted::DisplaySafeUrl;

use crate::middleware::OfflineError;
use crate::{FlatIndexError, html};
use uv_warnings::warn_user_once;

/// RFC 9457 Problem Details for HTTP APIs
///
Expand Down Expand Up @@ -242,7 +243,11 @@ impl Error {
}

/// Returns `true` if the error is due to the server not supporting HTTP range requests.
pub fn is_http_range_requests_unsupported(&self) -> bool {
pub fn is_http_range_requests_unsupported(
&self,
url: &DisplaySafeUrl,
index: Option<&IndexUrl>,
) -> bool {
match &*self.kind {
// The server doesn't support range requests (as reported by the `HEAD` check).
ErrorKind::AsyncHttpRangeReader(
Expand All @@ -261,6 +266,25 @@ impl Error {
return true;
}

// The server advertises range request support, but doesn't implement it correctly.
ErrorKind::AsyncHttpRangeReader(
_,
AsyncHttpRangeReaderError::RangeMismatch { .. }
| AsyncHttpRangeReaderError::ResponseTooShort { .. }
| AsyncHttpRangeReaderError::ResponseTooLong { .. },
) => {
let url = if let Some(index) = index {
index.url()
} else {
url
};
warn_user_once!(
"Invalid range request response from server that declares HTTP range request \
support, falling back to streaming: {url}"
);
return true;
}

// The server returned a "Method Not Allowed" error, indicating it doesn't support
// HEAD requests, so we can't check for range requests.
ErrorKind::WrappedReqwestError(_, err) => {
Expand Down Expand Up @@ -297,11 +321,27 @@ impl Error {
ErrorKind::Zip(_, ZipError::UpstreamReadError(err)) => {
if let Some(inner) = err.get_ref() {
if let Some(inner) = inner.downcast_ref::<AsyncHttpRangeReaderError>() {
if matches!(
inner,
match inner {
AsyncHttpRangeReaderError::HttpRangeRequestUnsupported
) {
return true;
| AsyncHttpRangeReaderError::ContentLengthMissing
| AsyncHttpRangeReaderError::ContentRangeMissing => {
return true;
}
AsyncHttpRangeReaderError::RangeMismatch { .. }
| AsyncHttpRangeReaderError::ResponseTooShort { .. }
| AsyncHttpRangeReaderError::ResponseTooLong { .. } => {
let url = if let Some(index) = index {
index.url()
} else {
url
};
warn_user_once!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be okay with this being a tracing warning, since it isn't necessarily something the user can proactively fix (if they don't control the server).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll cause users a bad time trying not understanding why everything is so slow, and the server problem won't be escalated to the responsible administrators.

"Invalid range request response from server that declares HTTP \
range request support, falling back to streaming: {url}"
);
return true;
}
_ => {}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ impl RegistryClient {
match result {
Ok(metadata) => return Ok(metadata),
Err(err) => {
if err.is_http_range_requests_unsupported() {
if err.is_http_range_requests_unsupported(url, index) {
// The range request version failed. Fall back to streaming the file to search
// for the METADATA file.
warn!("Range requests not supported for {filename}; streaming wheel");
Expand Down
Loading