From 9ede666fff64190af375e5e9eb0a875866cde530 Mon Sep 17 00:00:00 2001 From: Ryann Graham Date: Tue, 20 Jun 2023 11:58:53 -0700 Subject: [PATCH] cache: retry requests on HTTP 500 responses actions/cache occasionally gets 500 errors like actions/upload-artifact does, but it just fails instead of retrying like upload-artifact does. This adds retrying on 500 errors to @actions/cache the same way it was added to @actions/artifact in #833. --- packages/cache/__tests__/requestUtils.test.ts | 2 +- packages/cache/__tests__/saveCache.test.ts | 6 +++--- packages/cache/src/internal/requestUtils.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/cache/__tests__/requestUtils.test.ts b/packages/cache/__tests__/requestUtils.test.ts index 05fc573b..34e5268c 100644 --- a/packages/cache/__tests__/requestUtils.test.ts +++ b/packages/cache/__tests__/requestUtils.test.ts @@ -122,7 +122,7 @@ test('retry fails after exhausting retries', async () => { }) test('retry fails after non-retryable status code', async () => { - await testRetryExpectingError([TestResponse(500), TestResponse(200, 'Ok')]) + await testRetryExpectingError([TestResponse(501), TestResponse(200, 'Ok')]) }) test('retry works after error', async () => { diff --git a/packages/cache/__tests__/saveCache.test.ts b/packages/cache/__tests__/saveCache.test.ts index 4d0027be..72fcfb2c 100644 --- a/packages/cache/__tests__/saveCache.test.ts +++ b/packages/cache/__tests__/saveCache.test.ts @@ -186,7 +186,7 @@ test('save with reserve cache failure should fail', async () => { .spyOn(cacheHttpClient, 'reserveCache') .mockImplementation(async () => { const response: TypedResponse = { - statusCode: 500, + statusCode: 501, result: null, headers: {} } @@ -228,7 +228,7 @@ test('save with server error should fail', async () => { .spyOn(cacheHttpClient, 'reserveCache') .mockImplementation(async () => { const response: TypedResponse = { - statusCode: 500, + statusCode: 501, result: {cacheId}, headers: {} } @@ -282,7 +282,7 @@ test('save with valid inputs uploads a cache', async () => { .spyOn(cacheHttpClient, 'reserveCache') .mockImplementation(async () => { const response: TypedResponse = { - statusCode: 500, + statusCode: 501, result: {cacheId}, headers: {} } diff --git a/packages/cache/src/internal/requestUtils.ts b/packages/cache/src/internal/requestUtils.ts index 043c8a7c..76813534 100644 --- a/packages/cache/src/internal/requestUtils.ts +++ b/packages/cache/src/internal/requestUtils.ts @@ -26,6 +26,7 @@ export function isRetryableStatusCode(statusCode?: number): boolean { return false } const retryableStatusCodes = [ + HttpCodes.InternalServerError, HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout