You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bound and drain hand-rolled HTTP transport pools (#6495)
* Bound and drain hand-rolled HTTP transport pools
#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.
* Centralize idle-pool bounds and cover them with tests
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.
* Forward and assert CloseIdleConnections on all 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.
* Strengthen UserAgentTransport drain tests
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.
* Fix codespell: keep-alives -> keep-alive
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.
0 commit comments