Documentation
¶
Overview ¶
Package transport provides the HTTP retry layer and the RateLimit pacing layer that runpod.New installs.
Policy: idempotent requests (GET, HEAD, PUT, DELETE, OPTIONS) retry on 429, on 500/502/503/504, and on transport-level errors. Non-idempotent requests (POST, PATCH) are never retried: a 429 or a 5xx does not prove the write was not applied, since an API can perform the write and still answer with an error, so a replay could apply it twice. A Retry-After header (delay-seconds or HTTP-date, RFC 9110 §10.2.3) is respected up to MaxRetryAfter; otherwise delay is exponential backoff with equal jitter.
Two cases opt out of a retry that would otherwise apply. A request whose body cannot be rewound (a streamed body, where net/http could not record a GetBody) is never replayed, so even a 429 comes straight back to the caller. And a delay longer than what is left of the request's deadline is not waited out: the response is returned instead, so a caller holding a short timeout still sees the 429 and its Retry-After rather than an opaque deadline error.
Index ¶
Constants ¶
const ( DefaultMaxAttempts = 4 DefaultMinBackoff = 1 * time.Second DefaultMaxBackoff = 30 * time.Second DefaultMaxRetryAfter = 60 * time.Second )
The policy's defaults, used for any Retry field left at its zero value.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimit ¶ added in v2.3.0
type RateLimit struct {
Base http.RoundTripper
// MaxWait is the longest wait RateLimit takes on; 0 means
// DefaultMaxRetryAfter.
MaxWait time.Duration
// contains filtered or unexported fields
}
RateLimit is an http.RoundTripper that paces requests on the RateLimit response header the Runpod API sends. Once a response reports a window exhausted, the next request waits for that window to reset. A wait longer than MaxWait, or past the request's deadline, is skipped: the request goes out and the caller gets the API's 429 and its Retry-After.
A RateLimit paces only the requests that go through it; runpod.New gives each Client its own. The zero value is usable: nil Base means http.DefaultTransport.
func (*RateLimit) CloseIdleConnections ¶ added in v2.3.0
func (l *RateLimit) CloseIdleConnections()
CloseIdleConnections forwards to the underlying transport.
type Retry ¶
type Retry struct {
Base http.RoundTripper
MaxAttempts int
MinBackoff time.Duration
MaxBackoff time.Duration
MaxRetryAfter time.Duration
// Jitter returns a random float in [0, 1). Overridable for deterministic tests.
Jitter func() float64
}
Retry is an http.RoundTripper that retries per the package policy. The zero value is usable: nil Base falls back to http.DefaultTransport and zero limits fall back to the package defaults.
func (*Retry) CloseIdleConnections ¶
func (r *Retry) CloseIdleConnections()
CloseIdleConnections forwards to the underlying transport, so http.Client.CloseIdleConnections is not silently a no-op through this one.