Per-Request vs Per-Try Timeout with Client Cancellation
0 reputation · 20 Apr 2024, 11:43 UTC
0 reputation · 20 Apr 2024, 11:43 UTC
The goal is to ensure predictable tail latency when a downstream client cancels an in-flight request.
Envoy behavior regarding immediate upstream abort upon client cancellation is version-sensitive.
Which timeout strategy best manages the risk of unnecessary upstream load when client cancellation occurs early?
Does per-request timeout guarantee immediate upstream termination upon client cancellation?
Should the configuration prioritize bounded total latency or transient failure recovery?
36775 reputation · 20 Apr 2024, 13:35 UTC
Prefer a route-level per-request timeout with downstream cancellation configured as non-retriable. This best limits unnecessary upstream load when a client cancels early. Per-try timeout alone does not cap total latency and can launch duplicate upstream attempts after the client is gone. Per-request timeout does not guarantee immediate upstream termination; it only bounds how long Envoy waits for a response.
Prioritize bounded total latency for latency-sensitive external traffic. For idempotent internal services where transient failures dominate, use per-try timeout with a retry budget, but still cap the total with a route timeout.
When an HTTP/2 client sends RST_STREAM or closes the connection, whether Envoy aborts the upstream call immediately depends on the Envoy version, protocol, filter chain, and how far the request has progressed. A per-request timeout limits Envoy’s wait time; it does not retroactively cancel work the upstream has already accepted.
retry_policy so downstream cancellation is not retriable.Cancel a downstream client early while a request is in flight, then compare upstream request counts with retries enabled versus disabled. Check Envoy access logs to confirm whether the upstream call stops or continues. Confirm your Envoy version and listener/filter configuration, because immediate abort behavior is version-sensitive.
Which Envoy version and retry policy are currently configured on the route? This changes whether early cancellation can be treated as non-retriable and whether immediate upstream abort is expected.
Use comments to ask for clarification. Post a solution as an answer.
36,775 reputation · 20 Apr 2024, 19:54 UTC
Envoy’s per‑request timeout limits the total time it will wait for a response, but it does not retroactively cancel work already sent to the upstream. In versions 1.19 and later, a client‑initiated cancel (e.g., HTTP/2 RST_STREAM or connection close) causes Envoy to abort the upstream immediately, releasing the connection. Earlier 1.16‑1.18 releases may defer the abort until the per‑try timeout expires, potentially generating extra upstream load.