Skip to content

Commit a134371

Browse files
rbtcollinsdjc
authored andcommitted
Make download retries async
1 parent 2502b13 commit a134371

File tree

3 files changed

+31
-32
lines changed

3 files changed

+31
-32
lines changed

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ tempfile.workspace = true
8383
termcolor.workspace = true
8484
thiserror.workspace = true
8585
threadpool = "1"
86+
tokio-retry.workspace = true
8687
tokio.workspace = true
8788
toml = "0.8"
8889
tracing-opentelemetry = { workspace = true, optional = true }
@@ -144,6 +145,7 @@ tempfile = "3.8"
144145
termcolor = "1.2"
145146
thiserror = "1.0"
146147
tokio = { version = "1.26.0", default-features = false, features = ["macros", "rt-multi-thread"] }
148+
tokio-retry = { version = "0.3.0" }
147149
tokio-stream = { version = "0.1.14" }
148150
tracing = "0.1"
149151
tracing-opentelemetry = "0.24"

src/dist/manifestation.rs

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ mod tests;
77
use std::path::Path;
88

99
use anyhow::{anyhow, bail, Context, Result};
10-
use retry::delay::NoDelay;
11-
use retry::{retry, OperationResult};
10+
use tokio_retry::{strategy::FixedInterval, RetryIf};
1211

1312
use crate::currentprocess::{process, varsource::VarSource};
1413
use crate::dist::component::{
@@ -21,7 +20,7 @@ use crate::dist::manifest::{Component, CompressionKind, Manifest, TargetedPackag
2120
use crate::dist::notifications::*;
2221
use crate::dist::prefix::InstallPrefix;
2322
use crate::dist::temp;
24-
use crate::errors::{OperationError, RustupError};
23+
use crate::errors::RustupError;
2524
use crate::utils::utils;
2625

2726
pub(crate) const DIST_MANIFEST: &str = "multirust-channel-manifest.toml";
@@ -173,36 +172,22 @@ impl Manifestation {
173172

174173
let url_url = utils::parse_url(&url)?;
175174

176-
let downloaded_file =
177-
retry(
178-
NoDelay.take(max_retries),
179-
|| match crate::utils::utils::run_future(download_cfg.download(&url_url, &hash))
180-
{
181-
Ok(f) => OperationResult::Ok(f),
182-
Err(e) => {
183-
match e.downcast_ref::<RustupError>() {
184-
Some(RustupError::BrokenPartialFile) => {
185-
(download_cfg.notify_handler)(Notification::RetryingDownload(
186-
&url,
187-
));
188-
return OperationResult::Retry(OperationError(e));
189-
}
190-
Some(RustupError::DownloadingFile { .. }) => {
191-
(download_cfg.notify_handler)(Notification::RetryingDownload(
192-
&url,
193-
));
194-
return OperationResult::Retry(OperationError(e));
195-
}
196-
Some(_) => return OperationResult::Err(OperationError(e)),
197-
None => (),
198-
};
199-
OperationResult::Err(OperationError(e))
175+
let downloaded_file = utils::run_future(RetryIf::spawn(
176+
FixedInterval::from_millis(0).take(max_retries),
177+
|| download_cfg.download(&url_url, &hash),
178+
|e: &anyhow::Error| {
179+
// retry only known retriable cases
180+
match e.downcast_ref::<RustupError>() {
181+
Some(RustupError::BrokenPartialFile)
182+
| Some(RustupError::DownloadingFile { .. }) => {
183+
(download_cfg.notify_handler)(Notification::RetryingDownload(&url));
184+
true
200185
}
201-
},
202-
)
203-
.with_context(|| {
204-
RustupError::ComponentDownloadFailed(component.name(new_manifest))
205-
})?;
186+
_ => false,
187+
}
188+
},
189+
))
190+
.with_context(|| RustupError::ComponentDownloadFailed(component.name(new_manifest)))?;
206191

207192
things_downloaded.push(hash);
208193

0 commit comments

Comments
 (0)