From 064a0c569f7ea1d335a483b8451fc0ccdb9151cb Mon Sep 17 00:00:00 2001 From: kruskall <99559985+kruskall@users.noreply.github.com> Date: Sat, 31 Dec 2022 01:10:45 +0100 Subject: [PATCH] fix: close response body in http strategy (#718) * 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. * lint: assign error to empty var --- wait/http.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wait/http.go b/wait/http.go index 60dec1004b..67e1206b5d 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 {