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

client.baseRetryPolicy check if response is nil before accessing attributes #205

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) {
return true, nil
}

// Retry when the response is nil as this can indicate a closed connection or some other temporary condition
if resp == nil {
return true, nil
}

// 429 Too Many Requests is recoverable. Sometimes the server puts
// a Retry-After response header to indicate when the server is
// available to start processing request from client.
Expand Down
13 changes: 13 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1268,3 +1268,16 @@ func TestClient_RedirectWithBody(t *testing.T) {
t.Fatalf("Expected the client to be redirected 2 times, got: %d", atomic.LoadInt32(&redirects))
}
}

func TestClient_baseRetryPolicy(t *testing.T) {
t.Parallel()
var response *http.Response = nil

ok, err := baseRetryPolicy(response, nil)
if !ok {
t.Fatalf("expected %v, got %v", true, ok)
}
if err != nil {
t.Fatalf("no error expected")
}
}