Skip to content

fix: avoid HTTP healthcheck memory leak#134

Open
tionis wants to merge 1 commit into
encodeous:mainfrom
tionis:fix-memory-leak
Open

fix: avoid HTTP healthcheck memory leak#134
tionis wants to merge 1 commit into
encodeous:mainfrom
tionis:fix-memory-leak

Conversation

@tionis

@tionis tionis commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

This caused a small memory leak in my setup (roughly 1GB per day).

Copilot AI review requested due to automatic review settings July 10, 2026 00:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to prevent an HTTP-based prefix healthcheck from leaking resources over time by reusing an http.Client and ensuring response bodies are fully drained and closed.

Changes:

  • Replaced per-probe http.Get with a reusable http.Client (with timeout) and moved probe logic into checkHTTP.
  • Added explicit response-body draining (io.Copy(io.Discard, ...)) and closing.
  • Added a unit test to verify the response body is closed for both OK and non-OK status codes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
state/prefix_health.go Reworks the HTTP healthcheck loop to use a reusable client and explicitly drain/close response bodies.
state/prefix_health_test.go Adds a test to ensure the HTTP healthcheck closes response bodies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread state/prefix_health.go
Comment on lines +210 to +215
resp, err := client.Get(h.URL)
if err != nil {
h.lastMetric.Store(INF)
log.Debug("prefix healthcheck failed", "prefix", h.Prefix.String(), "url", h.URL, "error", err)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants