From 9c0fad2acb0272318aba76138a5b2e7cb3472235 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Thu, 19 Sep 2024 20:41:06 +0400 Subject: [PATCH] GHA cache: handle io.EOF when uploading a part (#788) * GHA cache: handle io.EOF when uploading a part And pass-through other errors that Actions Toolkit deems as retryable. * Fix comment placement * GHA cach: pass through the status code from a pre-signed request * Always return HTTP 502 when a request to pre-signed URL fails --- internal/agent/http_cache/ghacache/ghacache.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/agent/http_cache/ghacache/ghacache.go b/internal/agent/http_cache/ghacache/ghacache.go index 0463613f..3338d76a 100644 --- a/internal/agent/http_cache/ghacache/ghacache.go +++ b/internal/agent/http_cache/ghacache/ghacache.go @@ -210,14 +210,21 @@ func (cache *GHACache) updateUploadable(writer http.ResponseWriter, request *htt uploadPartResponse, err := http.DefaultClient.Do(uploadPartRequest) if err != nil { - fail(writer, request, http.StatusInternalServerError, "GHA cache failed to upload part "+ + // Return HTTP 502 to cause the cache-related code in the Actions Toolkit to make a re-try[1]. + // + // [1]: https://github.com/actions/toolkit/blob/6dd369c0e648ed58d0ead326cf2426906ea86401/packages/cache/src/internal/requestUtils.ts#L24-L34 + fail(writer, request, http.StatusBadGateway, "GHA cache failed to upload part "+ "for key %q, version %q and part %d: %v", uploadable.Key(), uploadable.Version(), partNumber, err) return } if uploadPartResponse.StatusCode != http.StatusOK { - fail(writer, request, http.StatusInternalServerError, "GHA cache failed to upload part "+ + // We pass through the status code here so that the cache-related + // code in the Actions Toolkit will hopefully make a re-try[1]. + // + // [1]: https://github.com/actions/toolkit/blob/6dd369c0e648ed58d0ead326cf2426906ea86401/packages/cache/src/internal/requestUtils.ts#L24-L34 + fail(writer, request, uploadPartResponse.StatusCode, "GHA cache failed to upload part "+ "for key %q, version %q and part %d: got HTTP %d", uploadable.Key(), uploadable.Version(), partNumber, uploadPartResponse.StatusCode)