Time limiting
When an application calls a remote API, a slow or unresponsive dependency is often worse than an outright error. A request that hangs holds onto a connection, a worker and memory for the entire duration, and under load these blocked operations pile up until they exhaust the resources the rest of the system depends on. Time limiting puts an upper bound on how long a call may wait on the remote API, so a sluggish service degrades into a fast, predictable failure instead of a slow, spreading one.
The pattern is simple: each wait gets a deadline. If the remote API has not answered within that budget, the call is abandoned and a timeout error is returned to the caller. The caller can then react immediately, by serving a fallback, failing cleanly, or letting another resilience pattern take over.
Configuration
HARP sits between your application and the remote APIs it calls, so it can enforce a deadline
without any change to application code. You configure it on its HTTP client with a timeout (opens in a new tab),
in seconds.
The timeout bounds each phase of a call on its own: connecting, sending the request, reading the response, and waiting for a free connection. It does not bound the whole call, so a slow response that keeps streaming can take longer than the timeout in total.
The timeout is global: there is no per-remote or per-endpoint value. Health probes have their own timeout.
[http_cache]
enabled = false
[http_client]
timeout = 10.0The timeout applies with the HTTP cache off, as in the example. Lowering the timeout makes calls fail faster when an upstream is slow; raising it gives slow but legitimate operations more room to complete.
What the caller gets depends on when the timeout strikes. Before the upstream sends its response headers, the caller
gets a 504 Gateway Timeout. In the middle of the body, there is no 504: the caller keeps the upstream's status and
gets a truncated body.
With the other resilience patterns
Time limiting works best alongside the other resilience patterns. By default, HARP does not retry after a timeout (see the retry pattern): the caller gets the error and decides.
With a liveness algorithm set, the circuit breaker counts a timeout, before or during the body, as a
network_error, which is in the default break_on. Without one, the default, a timeout takes no URL out of the pool.
HARP's own 504 never counts as http_5xx: only status codes sent by the upstream do.
Once a URL is out, callers get a 503 only if no other URL is left. Choosing a deadline is a balance: too generous and slow calls keep consuming resources, too strict and you turn transient slowness into avoidable errors.