Skip to content

Commit

Permalink
fix(healthchecks): Ensure HTTP response body is always closed
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Nov 11, 2024
1 parent acd61b5 commit ff91f0f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions internal/notifier/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ func (h *Healthchecks) SendStatus(ctx context.Context, status Status, log string

var resp *http.Response
for i := range 5 {
if resp, err = client.Do(req); err == nil {
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()
resp, err = client.Do(req)
_, _ = io.Copy(io.Discard, resp.Body)
_ = resp.Body.Close()

if resp.StatusCode < 300 {
return nil
}
if err == nil && resp.StatusCode < 300 {
return nil
}

backoff := time.Duration(i+1) * time.Duration(i+1) * time.Second
slog.Debug("Healthchecks ping failed", "try", i+1, "backoff", backoff)
select {
Expand Down

0 comments on commit ff91f0f

Please # to comment.