From 1fc15cca49d506c30b3a50df6f1e60856f995cdb Mon Sep 17 00:00:00 2001 From: "gcp-cherry-pick-bot[bot]" <98988430+gcp-cherry-pick-bot[bot]@users.noreply.github.com> Date: Mon, 13 Nov 2023 14:51:01 +0000 Subject: [PATCH] Close reponse right after succesful request (#8894) (#8896) Signed-off-by: AdamKorcz Co-authored-by: AdamKorcz <44787359+AdamKorcz@users.noreply.github.com> --- pkg/engine/apicall/apiCall.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/engine/apicall/apiCall.go b/pkg/engine/apicall/apiCall.go index ce4b3607ca99..2a13c0d4e32e 100644 --- a/pkg/engine/apicall/apiCall.go +++ b/pkg/engine/apicall/apiCall.go @@ -127,6 +127,7 @@ func (a *apiCall) executeServiceCall(ctx context.Context, apiCall *kyvernov1.API if err != nil { return nil, fmt.Errorf("failed to execute HTTP request for APICall %s: %w", a.entry.Name, err) } + defer resp.Body.Close() if resp.StatusCode < 200 || resp.StatusCode >= 300 { b, err := io.ReadAll(resp.Body) @@ -137,7 +138,6 @@ func (a *apiCall) executeServiceCall(ctx context.Context, apiCall *kyvernov1.API return nil, fmt.Errorf("HTTP %s", resp.Status) } - defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read data from APICall %s: %w", a.entry.Name, err)