transport

package
v2.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

func (*RateLimit) RoundTrip added in v2.3.0

func (l *RateLimit) RoundTrip(req *http.Request) (*http.Response, error)

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.

func (*Retry) RoundTrip

func (r *Retry) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL