The MeshRetry policy makes a client proxy try a failed request again, instead of returning
the failure to the caller. You configure it on the side of the proxy making the request.
Use this policy to absorb short failures, such as a destination restarting, a connection reset,
or a rate limit that clears in a second or two.
A new mesh doesn’t retry requests until you apply a MeshRetry. For more information, see
Defaults and disabling retries.
Retries multiply load on a struggling destination. Pair a retry policy with
MeshCircuitBreaker, and set perTryTimeout so a slow
destination cannot hold a retried request open for the whole route timeout.
A failed response doesn’t prove that the destination didn’t do anything. Retrying a payment or another
write can repeat its side effects. Only retry operations that are safe to repeat, or use an
application-level idempotency mechanism.
targetRef selects the client proxies that retry: Mesh, or Dataplane with labels.
to[].targetRef selects the destination the retries apply to: Mesh, MeshService,
MeshExternalService, MeshMultiZoneService, or MeshHTTPRoute. A MeshHTTPRoute limits
retries to the requests that route matches.
default holds the configuration under http, grpc, tcp, or a combination of them. At
least one is required.
The policy has no rules, because the caller decides whether to retry.
numRetries: 3 allows up to four attempts, including the original request. perTryTimeout: 2s
limits each attempt, and MeshTimeout sets the overall HTTP
response deadline. The proxy stops when the request succeeds, the retries run out, or the
overall deadline expires, so all three retries might not run.
The per-attempt timer only runs until the proxy starts sending the response to the caller. It
doesn’t limit a response that’s already streaming, so use MeshTimeout stream limits for that.
For more information, see
Envoy’s timeout behavior.
A new mesh has no MeshRetry, so a proxy attempts each request once. Unlike
MeshTimeout, retries have no built-in defaults, so your first
MeshRetry introduces retries.
When an effective HTTP configuration leaves out a field, the following values apply:
No numRetries: Envoy retries once.
No retryOn, or an empty list: the conditions are GatewayError, ConnectFailure, and
RefusedStream. An empty list doesn’t disable retries.
To disable retries, set the following:
HTTP: http.numRetries: 0.
gRPC: grpc.numRetries: 0.
TCP: tcp.maxConnectAttempt: 1. TCP counts total connection attempts, so this allows only
the first one.
The destination returns any 5xx, or doesn’t answer. Includes ConnectFailure and RefusedStream.
GatewayError
The destination returns 502, 503, or 504.
Reset
The destination doesn’t answer: disconnect, reset, or read timeout.
Retriable4xx
The destination returns 409. No other 4xx is covered.
ConnectFailure
The connection to the destination fails, including a connect timeout.
EnvoyRatelimited
The response has the x-envoy-ratelimited header.
RefusedStream
The destination resets the stream with REFUSED_STREAM.
Http3PostConnectFailure
An HTTP/3 request fails after connecting.
HttpMethodGet and other methods
Limits retries to that method. Without a named condition in the list, the default conditions (GatewayError, ConnectFailure, RefusedStream) apply. For example, HttpMethodGet with 5xx retries only failed GET requests.
A status code
The destination returns that HTTP status code, such as 500 or 429. If the list has no named condition, the default conditions also apply.
5xx is lowercase. 5XX is rejected, even though it appears as
the example value in the CRD and the OpenAPI schema. Every other named condition is
upper camel case.
TCP has no conditions. A connection is retried when it fails to open, and maxConnectAttempt
is the only setting. It counts total attempts, not retries after the first one. It doesn’t
replay application messages after an open connection breaks.
The following example allows up to five connection attempts from frontend to backend:
When a destination answers a rate limit with a header that says when to try again,
rateLimitedBackOff uses that instead of the exponential backoff. It accepts the following
fields:
resetHeaders (required): headers to read, tried in order and matched case-insensitively. The first one
that parses is used. Each header’s format is either Seconds for a number of seconds to
wait, or UnixTimestamp for a point in time.
maxInterval: the longest wait to accept, 300s by default. A header asking for a longer
wait is skipped instead of shortened, and the next header is tried.
If no header qualifies, the exponential backoff applies. Envoy also adds jitter, so the actual
delay varies. For more information, see
Envoy’s rate-limit backoff behavior.
The header only sets the wait after the response qualifies for a retry. The following example
retries only responses with x-envoy-ratelimited, so a plain 429 with only Retry-After
isn’t retried. If your backend signals rate limiting with 429, add the quoted status-code
condition "429":
By default, a retry can go back to the host that just failed. hostSelection accepts the
following predicates to change which hosts are eligible:
Predicate
Effect
OmitPreviousHosts
Skips hosts already tried for this request.
OmitHostsWithTags
Skips hosts with the given tags, which are required.
OmitPreviousPriorities
Skips priorities already tried. updateFrequency sets how often priority load is recalculated, and defaults to 2.
hostSelectionMaxAttempts caps how many times host selection is retried before the proxy uses
the last host it selected. It defaults to one reattempt. An http block that sets only
hostSelectionMaxAttempts is rejected, so set it alongside another http field.
Host selection picks another endpoint of the same backend. It doesn’t fail over to a different
MeshService, and it needs several eligible endpoints to make a difference.
A more specific policy overrides the fields it sets and inherits the rest from broader
policies. For example, changing only HTTP numRetries to 2 keeps a broader policy’s
per-attempt timeout. A retryOn list replaces the broader list instead of adding to it.
Removing the narrower policy restores the broader behavior, including retries the narrower
policy disabled.
Disable retries in the application, so you measure only the proxy. For example, three
application attempts through a proxy that allows three attempts per call can produce up to
nine backend attempts.
Make the destination fail in a controlled way, and count the attempts it receives. For the
first example, one request produces up to four attempts.
Confirm the response the client gets after the retries run out.
Test a slow failure separately, and confirm whether the overall request timeout ends the
request before every retry runs.
Unexpected result
Check
More attempts than expected
Retries in the application or in another proxy.
A slow request is never retried
Compare the per-attempt timeout with the overall request deadline, which may expire first.
A 429 isn’t retried
Match "429" explicitly, or confirm that the response has the header your condition requires.
A retry reaches the same endpoint
hostSelection and the number of eligible endpoints.
Retries continue after deleting your policy
Other MeshRetry policies that select the same traffic, and the application’s retry logic.