Repository navigation
fix(locald): stop leaking a connection per agent-metrics check on Go 1.27 - #381
Merged
Merged
Conversation
…1.27 The tunnel-proxy monitor checks agent-metrics every 10s with a fresh http.Transport and closes the response body without reading it. Since Go 1.27, closing an unread body drains it and returns the connection to the idle pool. The transport is discarded and has no idle timeout, so every check leaves a connection open through the tunnel for as long as the root daemon runs. Disable keep-alives on the check's transport. It still opens a new connection each time, which is what the fresh transport is for. Co-Authored-By: Claude Opus 5.5 <[email protected]>
davixcky
approved these changes
Sep 30, 2026
Contributor
There was a problem hiding this comment.
Verified
- Ran
TestGetAgentMetricsClosesConnon Go 1.27.1. It passes with the fix. WithDisableKeepAlivesremoved it fails with10 of 10 check connections still open. - Also ran libconnect#180's
TestProbeHealthClosesConnthe same way, with the same result. The libconnect bump still needs to land before the next CLI release; ENG-1272 tracks it. - Swept the rest of the CLI daemon for the same pattern. Devbox renewal, the gRPC clients and the MCP remote either use shared transports or close their connections, so there are no other leaks. There's one possible leak in libconnect
httpproxy, which the CLI doesn't run; ENG-1273 tracks it.
Two small points in getAgentMetrics. Neither blocks this PR; both came from the old code:
- The status code isn't checked, so a 5xx from agent-metrics counts as healthy.
cli.Getdoesn't use the monitor'sctx, so cancelling only takes effect after the 10s client timeout.http.NewRequestWithContext(ctx, …)would fix that.
Picks up signadot/libconnect#180 (control-plane proxy health check no longer leaks a tunnel session per check on Go 1.27), along with the ENG-1247 sweep fixes merged since 1316775 (xap, xaprevtun, high findings, etchosts line endings). Co-Authored-By: Claude Opus 5.5 <[email protected]>
The check used cli.Get, so cancelling the tunnel-proxy monitor only took effect after the 10s client timeout. Also document why the response status is ignored: any HTTP response shows the tunnel works, and a failure restarts localnet/name resolution, which can't fix agent-metrics. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Member
Author
|
Thanks @david, point 2 addressed, point 1 looks complex for this context, see commit msg. |
This was referenced Oct 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Part of the ENG-1267 follow-up sweep (signadot/signadot#7502 fixed the same bug in the tunnelserver).
Cause
The tunnel-proxy monitor in the root daemon checks
agent-metrics.signadot.svc:9090/metricsevery 10s while healthy. It uses a freshhttp.Transporteach time so the check opens a new connection, and it closes the response body without reading it.Since Go 1.27, closing an unread body drains it and returns the connection to the transport's idle pool. Nothing references the transport afterwards and it has no idle timeout, so every check leaves a connection open through the tunnel for as long as the daemon runs.
No released CLI is affected: v1.8.0 was built with Go 1.25.12, where closing an unread body closes the connection. The next release will be the first built with Go 1.27.
Changes
DisableKeepAlives: trueon the check's transport. Each check still opens a new connection.getAgentMetrics(target)so it can be tested.libconnect's control-plane proxy health check has the same bug; signadot/libconnect#180 fixes it. I'll add the libconnect bump to this PR once that merges.
Testing
TestGetAgentMetricsClosesConnruns the check 10 times against a local server and checks that the server sees every connection closed.DisableKeepAlivesremoved.go test ./...passes.🤖 Generated with Claude Code