Documentation
¶
Overview ¶
Package toolboxhttp is the HTTP transport sandboxd uses to reach a sandbox's toolbox over the network.
Index ¶
- Constants
- Variables
- func Client(timeout time.Duration) *http.Client
- func DeadPeerTimeout() time.Duration
- func DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func DialContextRetryRefused(ctx context.Context, network, addr string) (net.Conn, error)
- func ProxyClient(timeout time.Duration) *http.Client
- func SetDeadPeerTimeout(d time.Duration)
Constants ¶
const DefaultDeadPeerTimeout = 30 * time.Second
DefaultDeadPeerTimeout is how long a toolbox connection to a sandbox that stopped answering lives on (SB_TOOLBOX_DEAD_PEER_TIMEOUT).
const MinDeadPeerTimeout = 6 * time.Second
MinDeadPeerTimeout is the smallest timeout SetDeadPeerTimeout takes: the kernel counts keepalive time in whole seconds, and the probe interval is a sixth of the timeout.
Variables ¶
var ProxyTransport = func() *http.Transport { t := Transport.Clone() t.DialContext = DialContextRetryRefused return t }()
ProxyTransport is Transport whose dial is tried again while the toolbox refuses the connection (DialContextRetryRefused). The toolbox proxies use it: the v1 and Daytona reverse proxy and RoundTripToolbox (internal/service/toolbox_proxy.go) and E2B's runtime proxy (pkg/api/e2b/runtime_proxy.go). Probes keep Transport, so a probe of a toolbox that is down answers at once and the next probe tries again.
var Transport = func() *http.Transport { t := http.DefaultTransport.(*http.Transport).Clone() t.DisableKeepAlives = true t.DialContext = DialContext return t }()
Transport never keeps a connection open between calls. A sandbox's address outlives it: the next sandbox on the same Firecracker TAP slot or container IP gets it, and a VM restarted or resumed there has a fresh kernel. A pooled keep-alive connection to the old sandbox would be sent to the new one and reset (live: 72 of 80 concurrent execs into a fresh Firecracker sandbox, and a quarter of a create/exec/destroy churn, failed with 502 "connection reset by peer"). A local handshake per call costs tens of microseconds. WebSocket upgrades are unaffected: Go never marks a protocol switch "Connection: close", and an upgraded connection is never pooled.
Functions ¶
func DeadPeerTimeout ¶
DeadPeerTimeout is the current bound (0: off).
func DialContext ¶
DialContext dials a toolbox. Every network path from sandboxd to a toolboxd uses it (Transport, and the SSH gateway's session WebSocket), so a sandbox that dies without closing its connections (a killed gVisor sandbox or Firecracker VM: nothing is left to send a FIN or a reset, and its address goes silent) is noticed within DeadPeerTimeout instead of when the kernel gives up, minutes later (live: an exec into a gVisor sandbox killed by a fork bomb answered 502 after 3m18s).
func DialContextRetryRefused ¶ added in v0.6.12
DialContextRetryRefused is DialContext that dials again, after a short wait, while the toolbox refuses the connection: a live address with nothing listening on the port yet, the gap between a sandbox reported started (or toolboxd restarted inside it) and toolboxd binding its port.
It retries a refusal only. A refusal comes back at once, so the retry is cheap and bounded by dialRetryDelays. A timeout has already taken up to dialTimeout, and an unreachable address means the sandbox's network is gone; retrying those would only push the 502 back by up to minutes.
The retry is safe for any request, a body that cannot be re-read included: it happens inside the dial, before http.Transport writes a byte of the request. Nothing outside the dial is retried. A RoundTrip level retry would not be: Transport closes the request body when RoundTrip fails, a failed dial included, and an error after the dial may come after the request (or part of it) went out. Transport's own replay applies only to a reused connection, which DisableKeepAlives rules out.
http.Transport detaches the dial from the request's cancellation (the connection could serve another request), so a caller that gives up mid retry gets its answer at once while this dial ends within the budget; a connection made after that is closed unused.
func ProxyClient ¶ added in v0.6.12
ProxyClient is an http.Client over ProxyTransport (timeout 0: none).
func SetDeadPeerTimeout ¶
SetDeadPeerTimeout sets how long a connection whose sandbox stopped answering lives on; the daemon calls it once at boot. 0 turns the bound off (Go's default keepalive, about 2.5 minutes, and the kernel's retransmission limit, about 15 minutes). A positive value under MinDeadPeerTimeout is raised to it. It applies to connections dialed afterwards.
Types ¶
This section is empty.