Skip to content

Commit

Permalink
Close response to fix file descriptor leak
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Jul 19, 2023
1 parent 747f91b commit 46ad496
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 46ad496

Please sign in to comment.