query
on specific network errors and HTTP status codes (502, 503, 504). We donât retry after the body is consumed. The default retry strategy is Backoff and Jitter
. You can read more about our default retry strategy on the AWS Architecture Blog.
Mutations wonât be retried because they arenât idempotent.
-
enabled
: Enables the retry mechanism for GraphQL query operations. -
algorithm
: Select the algorithm for the retry. Currently, onlybackoff_jitter
is supported. Additional fields depend on the algorithm selection. -
expression
: The evaluated result of this expression is used to determine if a failed subgraph request should be retried. -
backoff_jitter
-
max_attempts
: The maximum number of attempts before the operation is considered a failure. -
interval
: The time duration between each retry attempt. Increase with every retry. -
max_duration
: The maximum allowable duration between retries (random).
-
Retries on 429 Errors
We do not retry on 429 errors by default, as 429 means âToo Many Requestsâ, indicating that the subgraph wants the router to slow down sending requests. If you wish to retry on 429 requests, you can modify the default expression as seen here. If you have explicitly enabled retrying on HTTP 429 and the subgraph responds with 429, we attempt to follow the specification described here. If aRetry-After
header is present with a valid, non-zero value, we will not use the default backoff algorithm duration and instead use that value as the interval duration. If the duration from Retry-After
exceeds the router configurationâs max_duration
, we will default to using max_duration
.
HTTP 429 used to be retried by default, but is not retried by default as of
router@0.247.0
. If you want to retry on 429, set an explicit expression in retry.expression
.Conditional retry with expressions
You can control when retries should occur using exprlang expressions. Unlike expressions used throughout the router, which can be found here, the structure of retry expressions is different. Setretry.expression
to a boolean expression evaluated on each subgraph attempt. When the expression returns true
, the router will retry (subject to the configured algorithm limits).
Retry expression reference
Retry expressions are evaluated per subgraph attempt and provide a focused context. The following fields are available:statusCode
(int): The status code (if present) of the subgraph responseerror
(string): The specific error that was returned because a response could not be received from the subgraph. Note that these errors are the direct errors reported by Go (as our router is based in Go)
The GitHub references to Go source in this section are best-effort and not exhaustive.
They are included to give you useful context so you can tailor retry error expressions to your needs.
-
IsHttpReadTimeout()
: Returns true if the error is an HTTP-specific timeout waiting for response headers. Internally, we check for âtimeout awaiting response headersâ as referenced in the Go standard library here. -
IsTimeout()
: Returns true for any timeout error (HTTP read timeouts, network timeouts, deadline exceeded, or direct syscall timeouts).- Read timeout as described in
IsHttpReadTimeout()
. - Any timeout error: In Go, the
net.Error
interface exposes aTimeout()
method; if it returnstrue
, the error is considered a timeout. - âi/o timeoutâ: Deadline exceeded; see reference.
syscall.ETIMEDOUT
: Low-level error indicating a connection timeout.
- Read timeout as described in
-
IsConnectionRefused()
: Returns true for connection refused errors (ECONNREFUSED
).- Internally: check
syscall.ECONNREFUSED
; otherwise, match âconnection refusedâ (reference).
- Internally: check
-
IsConnectionReset()
: Returns true for connection reset errors (ECONNRESET
).- Internally: check
syscall.ECONNRESET
; otherwise, match âconnection resetâ (reference).
- Internally: check
-
IsConnectionError()
: Returns true for connection-related errors (refused, reset, DNS resolution failures, TLS handshake errors). -
IsRetryableStatusCode()
: Returns true if the status code is one of:- 500: Internal Server Error
- 502: Bad Gateway
- 503: Service Unavailable
- 504: Gateway Timeout
Examples
Default retry expression
The following is the default retry expression used when retry is enabled, but no expression condition is explicitly specified.config.yaml
Donât retry on HTTP read timeouts
Sometimes you might wish to allow only lower-level timeouts (connection timeouts, etc.) to trigger retries. The following expression will allow you to do this by ignoring HTTP read timeouts. A good reason you might want this is because the subgraph takes time to respond because it is running some business logic that takes a long time, for which you do not want to retry as it will only result in the same business logic running again.config.yaml
Retry on 429 Requests
If you wish to retry on 429 requests, you could appendstatusCode == 429
to the default expression.
config.yaml