Skip to content

[rds/kubernetes] Time out calls to the API server - #1485

Merged
manugarg merged 1 commit into
mainfrom
k8s-client-timeout
Sep 12, 2026
Merged

manugarg merged 1 commit into
mainfrom
k8s-client-timeout

Conversation

@manugarg

@manugarg manugarg commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

The kubeapi client was built without an http.Client timeout and its requests carry no context, so only the cloned DefaultTransport's dial (30s) and TLS handshake (10s) timeouts applied. An API server that completes the handshake and then never sends response headers hangs getURL forever.

Each lister refreshes from a single goroutine driven by a ticker, so one stuck call freezes that resource type's refresh permanently: targets go stale silently and never recover without a restart.

Sets a 30s overall timeout, comfortably under the 60s default re_eval_sec so a slow call is abandoned before the next tick. Client.Timeout covers the whole request lifecycle including the body read in getURL, and survives newClient wrapping the transport in oauth2.Transport. oauth.K8STokenSource is local-file based, so nothing else in this path does I/O.

Testing

TestGetURLTimeout exercises the real getURL path against a test server that blocks until the request context is cancelled, plus an assertion in TestNewClientWithTLS that the constructed client carries the timeout. Removing Timeout from the http.Client fails the tests.

Rebased onto #1486, which landed first. That merge added a testK8sClient helper covering exactly this setup, so the test now uses it instead of standing up its own TLS server. Verified go build ./... and go test -race ./internal/rds/... on the combined tree, not just on this branch's original base.

Interaction with #1486

This was the riskier half when the two PRs were opened together: turning stalls into fast errors fed a bug where expand() emptied the cache on any error, so an API outage would have flapped targets in and out every 60s instead of leaving them quietly stale.

That is fixed on main as of #1486 — expand() now keeps the last good result when a refresh fails — so this change is strictly safer to merge than when it was written. A stall now surfaces as a logged warning and a retry on the next tick, with the existing targets left in place.

The kubeapi client was built without an http.Client timeout and its
requests carry no context, so only the cloned DefaultTransport's dial and
TLS handshake timeouts applied. An API server that completes the
handshake and then never sends response headers hung getURL forever.

Each lister refreshes from a single goroutine driven by a ticker, so one
stuck call freezes that resource type's refresh permanently: targets go
stale silently and never recover without a restart.

Set a 30s overall timeout, comfortably under the 60s default
re_eval_sec. Client.Timeout covers the whole request lifecycle including
the body read in getURL, and survives newClient wrapping the transport
in oauth2.Transport.
@manugarg
manugarg merged commit 89b203b into main Sep 12, 2026
13 checks passed
@manugarg
manugarg deleted the k8s-client-timeout branch September 16, 2026 01:04
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.

1 participant