Repository navigation
Bound and drain hand-rolled HTTP transport pools - #6495
Conversation
#6480 bounded and drained only the clients built by networking.HttpClientBuilder.Build. Several hand-rolled &http.Transport{} literals elsewhere left IdleConnTimeout at zero, so a pooled idle connection never expired and a dropped client pinned a socket plus its goroutine pair for the process lifetime. Separately, several wrapping RoundTrippers did not implement CloseIdleConnections, so http.Client.CloseIdleConnections type-asserted the outermost transport, missed the method, and silently became a no-op. Implements changes for issue #6483: - Bound the transport literals in pkg/auth/discovery, pkg/auth/oauth, and pkg/oauthproto (discovery, dcr) with the same host-scoped pool bounds Build applies - Add networking.ForwardCloseIdle so a wrapping RoundTripper forwards CloseIdleConnections without an ad-hoc anonymous assertion; use it from ValidatingTransport and the vmcp wrappers - Forward CloseIdleConnections from bearerTokenTransport, registry/auth.Transport, and oauthproto.UserAgentTransport (the last inline, since pkg/oauthproto cannot import pkg/networking) pkg/authz/authorizers/http builds no wrapper and uses http.DefaultTransport (or its Clone), which is already bounded and forwards the call, so it needs no change.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6495 +/- ##
=======================================
Coverage 78.25% 78.26%
=======================================
Files 770 770
Lines 75389 75456 +67
=======================================
+ Hits 58996 59052 +56
- Misses 16388 16399 +11
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jhrozek
left a comment
There was a problem hiding this comment.
Reviewed the pool-bounding and CloseIdleConnections-forwarding changes across all touched transports/wrappers. Verified the 90s/100/4 constants match networking.Build's existing defaults, the UserAgentTransport import-cycle rationale checks out, and each production change has a matching test. LGTM.
tgrunnagle
left a comment
There was a problem hiding this comment.
Multi-agent review — 4 specialists (concurrency/lifecycle, Go quality, test coverage, security). Codex cross-review skipped (CLI not installed).
Solid, correctly-scoped completion of #6480 / #6483. The fix is correct, SSRF-neutral (verified: the private-IP dialer only exists in the blockPrivateIPs branch, which also sets DisableKeepAlives, so pooling never skips a per-dial check), and the import-cycle constraints are correctly identified and documented. No blocking issues. Four MEDIUM quality/robustness items below are worth addressing before merge; none is a correctness bug in the shipped path.
| # | Severity | Finding |
|---|---|---|
| F1 | MEDIUM | Pool values (90s/100/4) hardcoded across 5 sites; 3 already import networking and could use exported constants |
| F2 | MEDIUM | 3 of 5 bounded transports (discovery.go ×2, oidc.go) have no test |
| F3 | MEDIUM | nil-Base NotPanics tests pass even if the fallback they claim to verify were removed |
| F4 | MEDIUM | mcp_session.go "twin" wrappers (documented "keep in sync") still swallow CloseIdleConnections |
| F5 | LOW | New wrappers lack var _ IdleConnectionCloser compile-time assertions |
| F6 | LOW | UserAgentTransport no-capability branch untested |
| F7 | LOW | server/discovery/health.go unix/npipe transports unbounded (out of scope — follow-up) |
INFO (no action): the UserAgentTransport inline anonymous assertion is justified (real networking→oauthproto cycle); closeIdleSpy per-package duplication is idiomatic.
Generated with Claude Code
Addresses #6495 review comments: - MEDIUM pkg/oauthproto/dcr.go (3925404488): the 90s/100/4 pool values were duplicated across five transport literals with only a comment to keep them in sync. Add networking.SetIdleConnBounds as the single source (Build now uses it too); the three cycle-free sites call it, and the two oauthproto leaf sites reference a local const block since pkg/networking imports pkg/oauthproto. - MEDIUM pkg/auth/discovery/discovery.go (3925404500): the two discovery.go transports and the oidc.go transport shipped untested. Extract each into a small package-private builder that calls SetIdleConnBounds, and assert the three bounds (and that blockPrivateIPs disables keep-alives) in unit tests. Also add compile-time IdleConnectionCloser assertions to networking's own ValidatingTransport and closeIdlerTransport wrappers.
Addresses #6495 review comments: - MEDIUM pkg/vmcp/client/client.go (3925404525): the session-backed twins authRoundTripper and identityRoundTripper in mcp_session.go implemented RoundTrip but not CloseIdleConnections, so they swallowed the drain the canonical twins forward. Their doc requires the invariant be kept in sync until #5333; mirror the forward with networking.ForwardCloseIdle. - LOW pkg/registry/auth/transport.go (3925404536): none of the new forwarding wrappers carried a compile-time assertion, so a rename or typo of CloseIdleConnections would compile and re-hide the pool. Add var _ networking.IdleConnectionCloser assertions to the wrappers (registry/auth.Transport, bearerTokenTransport, the vmcp wrappers, and the twins); UserAgentTransport asserts the local shape since pkg/oauthproto cannot import pkg/networking.
Addresses #6495 review comments: - MEDIUM pkg/oauthproto/useragent_test.go (3925404517): the nil-Base test claimed to verify the DefaultTransport fallback forwards, but a type assertion on a nil interface returns ok==false without panicking, so the test would still pass if the guard were removed. Soften the comment to state accurately that it only checks the nil-Base path does not panic. - LOW pkg/oauthproto/useragent_test.go (3925404540): the ok==false arm (a non-nil Base lacking CloseIdleConnections) was never exercised. Add a plainRoundTripper sub-case asserting a safe no-op.
|
F7 (LOW) — the |
Codespell flags the plural "keep-alives"; the rest of the tree uses the singular. Reword the comments and test messages added in this branch to match, unblocking the Spellcheck CI job.
Summary
#6480 bounded the connection pool in
networking.HttpClientBuilder.Build, butseveral hand-rolled
&http.Transport{}literals outside the builder set onlytheir two timeouts and left
IdleConnTimeoutat zero, so an idle pooledconnection never expires — a dropped client pins a socket and its goroutine pair
for the process lifetime. Separately, a wrapping
RoundTripperthat does notimplement and forward
CloseIdleConnectionssilently makeshttp.Client.CloseIdleConnectionsa no-op, re-hiding the pool that #6480 fixed.This PR closes both gaps for the sites called out in the issue.
networking.SetIdleConnBounds, one helper that setsIdleConnTimeout/MaxIdleConns/MaxIdleConnsPerHosttogether, and routeBuildand the hand-rolled transports through it so the bounds have a singlesource of truth (no more per-site literals that can drift).
pkg/auth/discoveryandpkg/auth/oauthinto a small package-private builderthat calls
SetIdleConnBounds, so the exact sites Bound the hand-rolled http.Transport pools outside networking.Build #6483 names are covered byunit tests rather than relying on a "mirrors Build" comment.
RoundTripperaCloseIdleConnectionsthat forwards to its base vianetworking.ForwardCloseIdle,so the call reaches the concrete
*http.Transportat the bottom of the chain.This includes the session-backed
mcp_session.gotwins, whose doc requires theinvariant be kept in sync with the canonical wrappers until [vMCP] Consolidate duplicate identity-propagation round-trippers into shared internal transport package #5333.
var _ networking.IdleConnectionClosercompile-time assertions to every wrapper, so a rename or typo of
CloseIdleConnectionsfails the build instead of re-hiding the pool.Closes #6483
Type of change
Test plan
task test)task lint-fix)New unit tests cover both halves of the fix:
TestSetIdleConnBoundspins the shared helper's values(
pkg/networking/http_client_test.go); per-site tests assert the built clientor transport carries the three fields, including both dial modes for the
SSRF-guarded builders (
pkg/auth/discovery/discovery_test.go,pkg/auth/oauth/oidc_test.go,pkg/oauthproto/dcr_test.go,pkg/oauthproto/discovery_test.go).RoundTrippertests assert each wrapper forwardsCloseIdleConnectionsto its base, is a safe no-op when the base lacks thecapability, and does not panic on a nil base
(
pkg/auth/dcr/resolver_test.go,pkg/oauthproto/useragent_test.go,pkg/registry/auth/transport_test.go);TestForwardCloseIdlecovers thehelper directly (
pkg/networking/http_client_test.go).Changes
pkg/networking/http_client.goSetIdleConnBoundsandForwardCloseIdlehelpers; routeBuildthroughSetIdleConnBounds;var _assertions onValidatingTransport/closeIdlerTransportpkg/auth/discovery/discovery.gonewDetectionClientandnewResourceMetadataTransport, both callingSetIdleConnBoundspkg/auth/oauth/oidc.gonewOIDCDiscoveryTransport, callingSetIdleConnBoundspkg/oauthproto/constants.gopkg/oauthproto/dcr.go,pkg/oauthproto/discovery.gopkg/auth/dcr/resolver.goCloseIdleConnectionsfrombearerTokenTransport;var _assertionpkg/registry/auth/transport.goCloseIdleConnectionsfrom the authTransport;var _assertionpkg/oauthproto/useragent.goCloseIdleConnectionsfromUserAgentTransport; local-shapevar _assertionpkg/vmcp/client/client.goForwardCloseIdle;var _assertions on the three wrapperspkg/vmcp/headerforward/transport.goForwardCloseIdle;var _assertionpkg/vmcp/session/internal/backend/mcp_session.goCloseIdleConnectionsfrom theauthRoundTripper/identityRoundTrippertwins;var _assertionsDoes this introduce a user-facing change?
No. This is an internal resource-lifecycle fix with no change to public APIs or
observable behavior.
Special notes for reviewers
pkg/authz/authorizers/http/http_client.gois intentionally NOT changed.The issue lists it under the
CloseIdleConnectionswrappers, but it useshttp.DefaultTransport(or a boundedClone) with no swallowing wrapper — itspool is already bounded and its
CloseIdleConnectionsalready reaches thepool. Flagging so anyone cross-checking the issue's site list does not read it
as a missed case.
pkg/oauthprotocannot importpkg/networking(networking importsoauthproto, so it would cycle). Its two leaf transports therefore reference a
local const block in
constants.gothat mirrors thenetworking.Buildboundsby hand, and
UserAgentTransport.CloseIdleConnectionsuses the equivalentinline
interface{ CloseIdleConnections() }assertion instead ofForwardCloseIdle. Both carry a comment explaining the cycle.IdleConnTimeout: 90s,MaxIdleConns: 100,MaxIdleConnsPerHost: 4) live once innetworking's constants (mirrored inoauthprotofor the cycle-blocked sites). Routing these hand-rolled transportsthrough the builder would be the better long-term fix but is a larger refactor
left out of scope here.
server/discovery/health.gounix/npipe transports are left as a follow-up(local IPC sockets, a different leak profile than the network pools this PR
targets).
Generated with Claude Code