Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry on HTTP 404 #172

Merged
merged 1 commit into from
Oct 16, 2024
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
5 changes: 5 additions & 0 deletions src/domain/release-archive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ describe("fetch", () => {

expect(axiosRetry).toHaveBeenCalledWith(axios, {
retries: 3,
retryCondition: expect.matchesPredicate((retryConditionFn: Function) => {
// Make sure HTTP 404 errors are retried.
let notFoundError = { response: { status: 404 } };
return retryConditionFn.call(this, notFoundError);
}),
retryDelay: expect.matchesPredicate((retryDelayFn: Function) => {
// Make sure the retry delays follow exponential backoff
// and the final retry happens after at least 1 minute total
Expand Down
9 changes: 9 additions & 0 deletions src/domain/release-archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ function exponentialDelay(
return axiosRetry.exponentialDelay(retryCount, error, delayFactor);
}

function defaultRetryPlus404(error: AxiosError): boolean {
// Publish-to-BCR needs to support retrying when GitHub returns 404
// in order to support automated release workflows that upload artifacts
// within a minute or so of publishing a release.
// Apart from this case, use the default retry condition.
return error.response.status === 404 || axiosRetry.isNetworkOrIdempotentRequestError(error);
}

async function download(url: string, dest: string): Promise<void> {
if (process.env.INTEGRATION_TESTING) {
// Point downloads to the standin github server
Expand All @@ -140,6 +148,7 @@ async function download(url: string, dest: string): Promise<void> {
retries: 3,
retryDelay: exponentialDelay,
shouldResetTimeout: true,
retryCondition: defaultRetryPlus404,
});

let response: AxiosResponse;
Expand Down