Skip to content

Commit e190a25

Browse files
authored
Merge pull request #3217 from ProvableHQ/make_parameter_downloads_more_robust
Make parameter downloads more robust
2 parents 7837311 + 48457ca commit e190a25

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,7 @@ workflows:
12791279
or pipeline.git.branch == "canary"
12801280
or pipeline.git.branch == "testnet"
12811281
or pipeline.git.branch == "mainnet"
1282-
or pipeline.git.branch == "mainnet-release-v460"
1283-
or pipeline.git.branch == "feat/cost_without_pk"
1282+
or pipeline.git.branch == "make_parameter_downloads_more_robust"
12841283
jobs:
12851284
- check-unused-dependencies # This can be cleaned up before releases
12861285
- check-cargo-semver-checks # This can be cleaned up before releases

parameters/src/macros.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,31 @@ macro_rules! impl_store_and_remote_fetch {
7777
println!("{}", output.dimmed());
7878
}
7979

80-
let response = reqwest::blocking::get(url)?;
81-
let bytes = response.bytes()?;
82-
buffer.extend_from_slice(&bytes);
80+
let host = url.split('/').nth(2).unwrap_or_default().to_string();
81+
let retry_policy = reqwest::retry::for_host(host)
82+
.max_retries_per_request(3)
83+
.classify_fn(|req_rep| {
84+
if req_rep.error().is_some() {
85+
return req_rep.retryable();
86+
}
87+
match req_rep.status() {
88+
Some(status) if status.is_server_error() || status.as_u16() == 429 => req_rep.retryable(),
89+
_ => req_rep.success(),
90+
}
91+
});
92+
93+
let client = reqwest::blocking::Client::builder()
94+
.redirect(reqwest::redirect::Policy::limited(10)) // Limit to 10 redirects.
95+
.retry(retry_policy)
96+
.build()?;
97+
98+
let mut response = client.get(url).send()?.error_for_status()?;
99+
response.copy_to(buffer)?;
83100

84101
#[cfg(not(feature = "no_std_out"))]
85102
{
86103
use colored::*;
87-
let size_in_megabytes = bytes.len() as u64 / 1_048_576;
104+
let size_in_megabytes = buffer.len() as u64 / 1_048_576;
88105
let output = format!("{:>15} - Download complete ({} MB)", "Installation", size_in_megabytes);
89106
println!("{}", output.dimmed());
90107
}

0 commit comments

Comments
 (0)