From 638c0d37df352b7e99d7f0ab0fc5586664bb6cf9 Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Fri, 30 Dec 2022 03:44:42 +0100 Subject: [PATCH 1/2] fix: close response body in http strategy From to the documentation: > If the returned error is nil, the Response will contain a non-nil body which the user is expected to close. Failed requests (due to wrong response or status code) were leaving open connections. Close the response body according to the documentation. --- wait/http.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wait/http.go b/wait/http.go index 60dec1004b..4a0b1bdbc8 100644 --- a/wait/http.go +++ b/wait/http.go @@ -217,9 +217,11 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge continue } if ws.StatusCodeMatcher != nil && !ws.StatusCodeMatcher(resp.StatusCode) { + resp.Body.Close() continue } if ws.ResponseMatcher != nil && !ws.ResponseMatcher(resp.Body) { + resp.Body.Close() continue } if err := resp.Body.Close(); err != nil { From bfb296dcbf7c5bf0c7b22fa80f1b1518c80d205c Mon Sep 17 00:00:00 2001 From: kruskal <99559985+kruskall@users.noreply.github.com> Date: Fri, 30 Dec 2022 20:44:06 +0100 Subject: [PATCH 2/2] lint: assign error to empty var --- wait/http.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wait/http.go b/wait/http.go index 4a0b1bdbc8..67e1206b5d 100644 --- a/wait/http.go +++ b/wait/http.go @@ -217,11 +217,11 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge continue } if ws.StatusCodeMatcher != nil && !ws.StatusCodeMatcher(resp.StatusCode) { - resp.Body.Close() + _ = resp.Body.Close() continue } if ws.ResponseMatcher != nil && !ws.ResponseMatcher(resp.Body) { - resp.Body.Close() + _ = resp.Body.Close() continue } if err := resp.Body.Close(); err != nil {