Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ jobs:
echo "EOF" >> "$GITHUB_OUTPUT"

cp dist-manifest.json "$BUILD_MANIFEST_NAME"
# The generated installer downloads the archive with a single `curl`
# (https://github.com/axodotdev/cargo-dist/pull/2311). GitHub Releases can answer HTTP 618
# for an expired signed link, which only --retry-all-errors retries. The grep fails the
# release if the template's download line changes.
# TODO(COD-4523): drop this step and `allow-dirty` once installers download from our CDN.
- name: Retry the installer's archive download
run: |
installer=target/distrib/codspeed-runner-installer.sh
sed -i 's/curl -sSfL /curl -sSfL --retry 5 --retry-all-errors /' "$installer"
grep -qF 'curl -sSfL --retry 5 --retry-all-errors "$1" -o "$2"' "$installer"
- name: "Upload artifacts"
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a
with:
Expand Down
6 changes: 5 additions & 1 deletion dist-workspace.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ install-updater = false
precise-builds = true
# `pr-run-mode = "upload"` would otherwise turn on a rust-cache step in every build job
cache-builds = false
# release.yml patches the generated installer (step "Retry the installer's archive download"),
# so `dist generate` must not overwrite it. To regenerate release.yml, drop this line, run
# `dist generate`, then restore that step and this line.
allow-dirty = ["ci"]

# Pins for the generated release.yml, which dependabot skips: bump them here, then run `dist generate`
# Pins for release.yml, which dependabot skips: bump them here, then regenerate it (see `allow-dirty`)
[dist.github-action-commits]
"actions/checkout" = "3d3c42e5aac5ba805825da76410c181273ba90b1" # v7.0.1
"actions/upload-artifact" = "043fb46d1a93c77aae656e7c1c64a875d1fc6a0a" # v7.0.1
Expand Down
53 changes: 32 additions & 21 deletions src/cli/run/helpers/download_file.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::binary_pins::PinnedBinary;
use crate::{prelude::*, request_client::DOWNLOAD_CLIENT};
use reqwest_retry::{
RetryDecision, RetryPolicy, Retryable, default_on_request_success, policies::ExponentialBackoff,
};
use reqwest_retry::{RetryDecision, RetryPolicy, policies::ExponentialBackoff};
use std::path::Path;
use std::time::SystemTime;

Expand Down Expand Up @@ -36,14 +34,13 @@ async fn download_file(url: &Url, path: &Path) -> Result<(), AttemptError> {
.get(url.clone())
.send()
.await
.map_err(|e| AttemptError::Transient(anyhow!("Failed to download file: {e}")))?;
.map_err(|e| AttemptError::Transient(anyhow!(e)))?;

if !response.status().is_success() {
let error = anyhow!("Failed to download file: {}", response.status());
return Err(match default_on_request_success(&response) {
Some(Retryable::Transient) => AttemptError::Transient(error),
_ => AttemptError::Fatal(error),
});
// Any error status is retried: GitHub Releases answers HTTP 618 for an expired signed link,
// and a new request to the release URL gets a fresh one.
let status = response.status();
if !status.is_success() {
return Err(AttemptError::Transient(anyhow!("HTTP {status}")));
}

let content = response
Expand Down Expand Up @@ -108,7 +105,17 @@ async fn download_and_verify(url: &Url, expected_sha256: &str, path: &Path) -> R
tokio::time::sleep(wait).await;
n_past_retries += 1;
}
RetryDecision::DoNotRetry => return Err(error),
RetryDecision::DoNotRetry => {
let hint = if url.host_str() == Some("github.com") {
"\nThis file is hosted on GitHub Releases. Re-run the job, and check https://www.githubstatus.com if it keeps failing."
} else {
""
};
bail!(
"Failed to download {url} after {} attempts: {error:#}.{hint}",
n_past_retries + 1
);
}
}
}
}
Expand Down Expand Up @@ -263,8 +270,11 @@ mod tests {
.await
.expect_err("persistent truncated bodies should fail the download");

let prefix = format!("Failed to download {url} after {attempts} attempts: ");
assert!(
error.to_string().contains("Failed to read response"),
error
.to_string()
.starts_with(&(prefix + "Failed to read response")),
"unexpected error: {error}"
);
assert_eq!(request_count.load(Ordering::SeqCst), attempts);
Expand All @@ -287,19 +297,20 @@ mod tests {
}

#[tokio::test]
async fn does_not_retry_client_errors() {
let (url, request_count) = spawn_scripted_server(vec![ScriptedResponse::Status(404)]);
async fn retries_any_error_status_and_recovers() {
let (url, request_count) = spawn_scripted_server(vec![
ScriptedResponse::Status(618),
ScriptedResponse::Status(404),
ScriptedResponse::Body(GOOD_BODY),
]);
let file = NamedTempFile::new().unwrap();

let error = download_and_verify(&url, &sha256::digest(GOOD_BODY), file.path())
download_and_verify(&url, &sha256::digest(GOOD_BODY), file.path())
.await
.expect_err("a 404 should fail the download");
.expect("download should recover from error statuses");

assert!(
error.to_string().contains("404"),
"unexpected error: {error}"
);
assert_eq!(request_count.load(Ordering::SeqCst), 1);
assert_eq!(std::fs::read(file.path()).unwrap(), GOOD_BODY);
assert_eq!(request_count.load(Ordering::SeqCst), 3);
}

#[tokio::test]
Expand Down
30 changes: 20 additions & 10 deletions src/executor/helpers/introspected_golang/go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,26 @@ install_go_runner() {
}
trap cleanup_go_runner_installer RETURN

curl -fsSL "$download_url" -o "$installer_path"

local actual_sha256
actual_sha256=$(sha256_file "$installer_path")
if [ "$actual_sha256" != "$expected_sha256" ]; then
echo "ERROR: Hash mismatch for $download_url: expected $expected_sha256, got $actual_sha256" >&2
exit 1
fi

bash "$installer_path" --quiet
# GitHub Releases fails transiently (5xx, HTTP 618 for an expired signed link). The installer
# downloads the archive with a single curl, so the whole install is retried.
local attempt actual_sha256
for attempt in 1 2 3 4 5 6; do
if curl -fsSL "$download_url" -o "$installer_path"; then
actual_sha256=$(sha256_file "$installer_path")
if [ "$actual_sha256" != "$expected_sha256" ]; then
echo "ERROR: Hash mismatch for $download_url: expected $expected_sha256, got $actual_sha256" >&2
exit 1
fi
bash "$installer_path" --quiet && return
fi
if [ "$attempt" -lt 6 ]; then
echo "WARNING: Attempt $attempt/6 to install codspeed-go-runner v$version failed. Retrying in $((2 ** (attempt - 1)))s." >&2
sleep $((2 ** (attempt - 1)))
fi
done
echo "ERROR: Failed to install codspeed-go-runner v$version after 6 attempts." >&2
echo "It is hosted on GitHub Releases. Re-run the job, and check https://www.githubstatus.com if it keeps failing." >&2
exit 1
}


Expand Down
Loading