Skip to content

Commit

Permalink
fix: check for nil response in the retry handler (#4364)
Browse files Browse the repository at this point in the history
  • Loading branch information
slntopp authored Jul 18, 2024
1 parent 968a5e3 commit a47aaae
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions providers/github/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit a47aaae

Please sign in to comment.