Log the duration we took before erroring (#18231)

We previously errored due to not having long enough backoff, and there
were questions about how long the retries are, so let's log this on
failure.
This commit is contained in:
konsti
2026-03-06 15:51:10 +01:00
committed by GitHub
parent 686f43e67e
commit 401661ee22
9 changed files with 160 additions and 92 deletions
+14 -2
View File
@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
use std::pin::Pin;
use std::str::FromStr;
use std::task::{Context, Poll};
use std::time::{Duration, Instant, SystemTimeError};
use std::{env, io};
use futures::TryStreamExt;
@@ -54,11 +55,16 @@ pub enum Error {
TooManyParts(String),
#[error("Failed to download {0}")]
NetworkError(DisplaySafeUrl, #[source] WrappedReqwestError),
#[error("Request failed after {retries} {subject}", subject = if *retries > 1 { "retries" } else { "retry" })]
#[error(
"Request failed after {retries} {subject} in {duration:.1}s",
subject = if *retries > 1 { "retries" } else { "retry" },
duration = duration.as_secs_f32()
)]
NetworkErrorWithRetries {
#[source]
err: Box<Self>,
retries: u32,
duration: Duration,
},
#[error("Failed to download {0}")]
NetworkMiddlewareError(DisplaySafeUrl, #[source] anyhow::Error),
@@ -116,6 +122,8 @@ pub enum Error {
BuildVersion(#[from] BuildVersionError),
#[error("No download URL found for Python")]
NoPythonDownloadUrlFound,
#[error(transparent)]
SystemTime(#[from] SystemTimeError),
}
impl Error {
@@ -1183,6 +1191,7 @@ impl ManagedPythonDownload {
Err(Error::NetworkErrorWithRetries {
err: Box::new(err),
retries: retry_state.total_retries(),
duration: retry_state.duration()?,
})
} else {
Err(err)
@@ -1698,12 +1707,14 @@ impl Error {
url: DisplaySafeUrl,
err: reqwest::Error,
retries: Option<u32>,
start: Instant,
) -> Self {
let err = Self::NetworkError(url, WrappedReqwestError::from(err));
if let Some(retries) = retries {
Self::NetworkErrorWithRetries {
err: Box::new(err),
retries,
duration: start.elapsed(),
}
} else {
err
@@ -1815,6 +1826,7 @@ async fn read_url(
Ok((Either::Left(reader), Some(size)))
} else {
let start = Instant::now();
let response = client
.for_host(url)
.get(Url::from(url.clone()))
@@ -1830,7 +1842,7 @@ async fn read_url(
// Check the status code.
let response = response
.error_for_status()
.map_err(|err| Error::from_reqwest(url.clone(), err, retry_count))?;
.map_err(|err| Error::from_reqwest(url.clone(), err, retry_count, start))?;
let size = response.content_length();
let stream = response