Skip to content

Commit 15e52b0

Browse files
committed
Auto merge of #115543 - Kobzol:opt-dist-retry-download, r=Mark-Simulacrum
Retry download of rustc-perf in opt-dist This should help resolving spurious network errors. It also increases the timeout for the archive download. r? `@Mark-Simulacrum`
2 parents 8cfaf70 + c98455f commit 15e52b0

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/tools/opt-dist/src/environment/windows.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use crate::environment::Environment;
22
use crate::exec::cmd;
33
use crate::utils::io::move_directory;
4+
use crate::utils::retry_action;
45
use camino::Utf8PathBuf;
56
use std::io::Cursor;
7+
use std::time::Duration;
68
use zip::ZipArchive;
79

810
pub(super) struct WindowsEnvironment {
@@ -43,7 +45,15 @@ impl Environment for WindowsEnvironment {
4345
const PERF_COMMIT: &str = "8b2ac3042e1ff2c0074455a0a3618adef97156b1";
4446

4547
let url = format!("https://ci-mirrors.rust-lang.org/rustc/rustc-perf-{PERF_COMMIT}.zip");
46-
let response = reqwest::blocking::get(url)?.error_for_status()?.bytes()?.to_vec();
48+
let client = reqwest::blocking::Client::builder()
49+
.timeout(Duration::from_secs(60 * 2))
50+
.connect_timeout(Duration::from_secs(60 * 2))
51+
.build()?;
52+
let response = retry_action(
53+
|| Ok(client.get(&url).send()?.error_for_status()?.bytes()?.to_vec()),
54+
"Download rustc-perf archive",
55+
5,
56+
)?;
4757

4858
let mut archive = ZipArchive::new(Cursor::new(response))?;
4959
archive.extract(self.rustc_perf_dir())?;

src/tools/opt-dist/src/utils/mod.rs

+19
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod io;
33
use crate::environment::Environment;
44
use crate::utils::io::{delete_directory, get_files_from_dir};
55
use humansize::{format_size, BINARY};
6+
use std::time::Duration;
67
use sysinfo::{DiskExt, RefreshKind, System, SystemExt};
78

89
pub fn format_env_variables() -> String {
@@ -70,6 +71,24 @@ pub fn with_log_group<F: FnOnce() -> R, R>(group: &str, func: F) -> R {
7071
}
7172
}
7273

74+
#[allow(unused)]
75+
pub fn retry_action<F: Fn() -> anyhow::Result<R>, R>(
76+
action: F,
77+
name: &str,
78+
count: u64,
79+
) -> anyhow::Result<R> {
80+
for attempt in 0..count {
81+
match action() {
82+
Ok(result) => return Ok(result),
83+
Err(error) => {
84+
log::error!("Failed to perform action `{name}`, attempt #{attempt}: {error:?}");
85+
std::thread::sleep(Duration::from_secs(5));
86+
}
87+
}
88+
}
89+
Err(anyhow::anyhow!("Failed to perform action `{name}` after {count} retries"))
90+
}
91+
7392
fn is_in_ci() -> bool {
7493
std::env::var("GITHUB_ACTIONS").is_ok()
7594
}

0 commit comments

Comments
 (0)