Skip to content

fix(locald): stop leaking a connection per agent-metrics check on Go 1.27 - #381

Merged
scott-cotton merged 3 commits into
mainfrom
eng-1267-tpmonitor-keepalives
Oct 1, 2026
Merged

scott-cotton merged 3 commits into
mainfrom
eng-1267-tpmonitor-keepalives

Conversation

@scott-cotton

Copy link
Copy Markdown
Member

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/metrics every 10s while healthy. It uses a fresh http.Transport each 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: true on the check's transport. Each check still opens a new connection.
  • The check moves into 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

  • New TestGetAgentMetricsClosesConn runs the check 10 times against a local server and checks that the server sees every connection closed.
    • Passes with the fix.
    • Fails on Go 1.27.1 with DisableKeepAlives removed.
  • go test ./... passes.

🤖 Generated with Claude Code

…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]>

@cursor cursor Bot 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.

Risk: low. Approved; Cursor Bugbot and Cursor Security Agent were not present after the first check poll, so those signals were skipped. No reviewers were assigned.

Open in Web View Automation 

Sent by Cursor Approval Agent: Pull Request Approver

@davixcky davixcky left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verified

  • Ran TestGetAgentMetricsClosesConn on Go 1.27.1. It passes with the fix. With DisableKeepAlives removed it fails with 10 of 10 check connections still open.
  • Also ran libconnect#180's TestProbeHealthClosesConn the 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:

  1. The status code isn't checked, so a 5xx from agent-metrics counts as healthy.
  2. cli.Get doesn't use the monitor's ctx, so cancelling only takes effect after the 10s client timeout. http.NewRequestWithContext(ctx, …) would fix that.

scott-cotton and others added 2 commits September 30, 2026 16:51
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]>
@scott-cotton

Copy link
Copy Markdown
Member Author

Thanks @david, point 2 addressed, point 1 looks complex for this context, see commit msg.

@scott-cotton
scott-cotton merged commit f25d958 into main Oct 1, 2026
1 check passed
@scott-cotton
scott-cotton deleted the eng-1267-tpmonitor-keepalives branch October 1, 2026 09:23
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