From bab98bddc1b83c74cf4059fe53bafc6ad5417d7e Mon Sep 17 00:00:00 2001 From: Jonathan Innis Date: Wed, 19 Jul 2023 11:11:31 -0700 Subject: [PATCH] Close response to fix file descriptor leak (#416) --- pkg/operator/operator.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 42143a15a2..f08b2f1abd 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -190,10 +190,15 @@ func webhookChecker(ctx context.Context) healthz.Checker { if err != nil { return err } + // Close the body to avoid leaking file descriptors + // Always read the body so we can re-use the connection: https://stackoverflow.com/questions/17948827/reusing-http-connections-in-go + _, _ = io.ReadAll(res.Body) + res.Body.Close() + // If there is a server-side error or path not found, // consider liveness to have failed if res.StatusCode >= 500 || res.StatusCode == 404 { - return fmt.Errorf("webhook probe failed, %s", lo.Must(io.ReadAll(res.Body))) + return fmt.Errorf("webhook probe failed with status code %d", res.StatusCode) } return nil }