From d30f59af8755ce1eefe711028cd2153c865ea68f Mon Sep 17 00:00:00 2001 From: tty2 Date: Fri, 8 Sep 2023 20:30:00 +0100 Subject: [PATCH 1/3] client.baseRetryPolicy check if response is nil before accessing attributes --- client.go | 6 ++++++ client_test.go | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/client.go b/client.go index cad96bd..1eef396 100644 --- a/client.go +++ b/client.go @@ -28,6 +28,7 @@ import ( "bytes" "context" "crypto/x509" + "errors" "fmt" "io" "io/ioutil" @@ -492,6 +493,11 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) { return true, nil } + // check if is nil to make below attributes access safe + if resp == nil { + return false, errors.New("response is 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. diff --git a/client_test.go b/client_test.go index 5aaed05..ce645eb 100644 --- a/client_test.go +++ b/client_test.go @@ -978,3 +978,16 @@ func TestClient_StandardClient(t *testing.T) { t.Fatalf("expected %v, got %v", client, v) } } + +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", false, ok) + } + if err == nil { + t.Fatalf("should error") + } +} From a137ae4d5fb64aaae590bb4ba903d9519cc12181 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 13 May 2024 18:38:08 +0100 Subject: [PATCH 2/3] Update client.go Co-authored-by: Tom Bamford --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index 1eef396..1f8b323 100644 --- a/client.go +++ b/client.go @@ -495,7 +495,7 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) { // check if is nil to make below attributes access safe if resp == nil { - return false, errors.New("response is nil") + return true, nil } // 429 Too Many Requests is recoverable. Sometimes the server puts From 0ab62fc276a87804851d816a428c3901ca62c0cf Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 13 May 2024 18:38:23 +0100 Subject: [PATCH 3/3] Update client.go Co-authored-by: Tom Bamford --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index 1f8b323..95bfd5f 100644 --- a/client.go +++ b/client.go @@ -493,7 +493,7 @@ func baseRetryPolicy(resp *http.Response, err error) (bool, error) { return true, nil } - // check if is nil to make below attributes access safe + // Retry when the response is nil as this can indicate a closed connection or some other temporary condition if resp == nil { return true, nil }