Skip to content

Commit 9b128e4

Browse files
authored
Rollup merge of rust-lang#45209 - kennytm:treat-checksum-error-as-download-error, r=Mark-Simulacrum
rustbuild: Make openssl download more reliable. 1. Add `-f` flag to curl, so when the server returns 403 or 500 it will fail immediately. 2. Moved the checksum part into the retry loop, assuming checksum failure is due to broken download that can be fixed by downloading again. This PR is created responding to two recent spurious failures in rust-lang#45075 (comment) and rust-lang#45030 (comment). r? @Mark-Simulacrum , cc @aidanhs
2 parents 64cc5ec + 90d58a3 commit 9b128e4

File tree

1 file changed

+37
-20
lines changed

1 file changed

+37
-20
lines changed

src/bootstrap/native.rs

+37-20
Original file line numberDiff line numberDiff line change
@@ -352,34 +352,51 @@ impl Step for Openssl {
352352
// originally from https://www.openssl.org/source/...
353353
let url = format!("https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/{}",
354354
name);
355-
let mut ok = false;
355+
let mut last_error = None;
356356
for _ in 0..3 {
357357
let status = Command::new("curl")
358358
.arg("-o").arg(&tmp)
359+
.arg("-f") // make curl fail if the URL does not return HTTP 200
359360
.arg(&url)
360361
.status()
361362
.expect("failed to spawn curl");
362-
if status.success() {
363-
ok = true;
364-
break
363+
364+
// Retry if download failed.
365+
if !status.success() {
366+
last_error = Some(status.to_string());
367+
continue;
365368
}
369+
370+
// Ensure the hash is correct.
371+
let mut shasum = if target.contains("apple") || build.build.contains("netbsd") {
372+
let mut cmd = Command::new("shasum");
373+
cmd.arg("-a").arg("256");
374+
cmd
375+
} else {
376+
Command::new("sha256sum")
377+
};
378+
let output = output(&mut shasum.arg(&tmp));
379+
let found = output.split_whitespace().next().unwrap();
380+
381+
// If the hash is wrong, probably the download is incomplete or S3 served an error
382+
// page. In any case, retry.
383+
if found != OPENSSL_SHA256 {
384+
last_error = Some(format!(
385+
"downloaded openssl sha256 different\n\
386+
expected: {}\n\
387+
found: {}\n",
388+
OPENSSL_SHA256,
389+
found
390+
));
391+
continue;
392+
}
393+
394+
// Everything is fine, so exit the retry loop.
395+
last_error = None;
396+
break;
366397
}
367-
if !ok {
368-
panic!("failed to download openssl source")
369-
}
370-
let mut shasum = if target.contains("apple") || build.build.contains("netbsd") {
371-
let mut cmd = Command::new("shasum");
372-
cmd.arg("-a").arg("256");
373-
cmd
374-
} else {
375-
Command::new("sha256sum")
376-
};
377-
let output = output(&mut shasum.arg(&tmp));
378-
let found = output.split_whitespace().next().unwrap();
379-
if found != OPENSSL_SHA256 {
380-
panic!("downloaded openssl sha256 different\n\
381-
expected: {}\n\
382-
found: {}\n", OPENSSL_SHA256, found);
398+
if let Some(error) = last_error {
399+
panic!("failed to download openssl source: {}", error);
383400
}
384401
t!(fs::rename(&tmp, &tarball));
385402
}

0 commit comments

Comments
 (0)