From a47aaae3b61105ad3a1789bedaeb4caa08b3d4b9 Mon Sep 17 00:00:00 2001 From: Mikita Iwanowski Date: Thu, 18 Jul 2024 18:06:30 +0200 Subject: [PATCH] fix: check for nil response in the retry handler (#4364) --- providers/github/connection/connection.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/github/connection/connection.go b/providers/github/connection/connection.go index 04dc0be30a..e4fff9c38d 100644 --- a/providers/github/connection/connection.go +++ b/providers/github/connection/connection.go @@ -180,7 +180,7 @@ func newGithubRetryableClient(httpClient *http.Client) *http.Client { retryClient.CheckRetry = func(ctx context.Context, resp *http.Response, err error) (bool, error) { // Default Retry Policy would not retry on 403 (adding 429 for good measure) - if resp.StatusCode == 403 || resp.StatusCode == 429 { + if resp != nil && (resp.StatusCode == 403 || resp.StatusCode == 429) { // Primary and Secondary rate limit if resp.Header.Get("x-ratelimit-remaining") == "0" { return true, nil // Should be retried after the rate limit reset (duration handled by Backoff) @@ -189,7 +189,7 @@ func newGithubRetryableClient(httpClient *http.Client) *http.Client { return retryablehttp.DefaultRetryPolicy(ctx, resp, err) } retryClient.Backoff = func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration { - if resp.StatusCode == 403 || resp.StatusCode == 429 { + if resp != nil && (resp.StatusCode == 403 || resp.StatusCode == 429) { // Secondary limit if resp.Header.Get("retry-after") != "" { sec, err := strconv.ParseInt(resp.Header.Get("retry-after"), 10, 64) // retry-after - The number of seconds to wait before making a follow-up request