You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Upstreams are tried sequentially, in priority order.
224
225
* Each eligible upstream is tried at most once per request.
225
226
* By default, rcpx continues to the next upstream on any transport error, or on HTTP status `429`, `502`, `503`, `504`.
226
-
* An attempt succeeds when `err == nil` and the status code is not `429`, `502`, `503`, or `504`.
227
+
* An attempt succeeds when `err == nil` and the status code is not retryable.
227
228
* Other HTTP status codes are treated as success from rcpx's perspective and returned unchanged.
228
229
* JSON-RPC response bodies are not inspected. A JSON-RPC error returned with HTTP `200` is returned unchanged.
229
230
* If the request context is canceled or deadline exceeded, rcpx returns immediately and does not consult the retry policy.
@@ -274,6 +275,21 @@ rcpx handles misbehaving base transports defensively:
274
275
* It will not return `(nil, nil)` from `RoundTrip`; if that happens, rcpx returns an error.
275
276
* If a base transport returns both `resp != nil` and `err != nil`, rcpx closes `resp.Body` and treats it as an error to avoid leaks.
276
277
278
+
### Additional retryable HTTP statuses
279
+
280
+
```go
281
+
typeConfigstruct {
282
+
AdditionalRetryableStatusCodes []int
283
+
// ...
284
+
}
285
+
```
286
+
287
+
`AdditionalRetryableStatusCodes` adds status codes to the built-in retryable set: `429`, `502`, `503`, and `504`.
288
+
289
+
For example, `[]int{500}` makes HTTP `500` retryable in addition to the defaults. Duplicates are ignored, and values must be three-digit HTTP status codes.
290
+
291
+
Retryable status classification happens before `RetryPolicy` is called.
292
+
277
293
### Retry policy
278
294
279
295
```go
@@ -289,9 +305,9 @@ You can override the default retry or failover behavior with `Config.RetryPolicy
289
305
* JSON-RPC info (best-effort): `Method`, `Batch`
290
306
* `StatusCode` (0 if no HTTP response was obtained)
291
307
* `Err` (the error from the base transport, if any)
292
-
* `RetryableByDefault` (rcpx's default classification for this outcome)
308
+
* `RetryableByDefault` (whether rcpx classifies the outcome as retryable)
293
309
294
-
`RetryableByDefault` is true for transport errors (`Err != nil`) and for HTTP status `429`, `502`, `503`, `504`.
310
+
`RetryableByDefault` is true for transport errors (`Err != nil`), for HTTP status `429`, `502`, `503`, `504`, and for statuses configured with `AdditionalRetryableStatusCodes`.
295
311
296
312
The retry policy is only consulted after rcpx has classified an attempt as non-success and there is another eligible upstream to try.
297
313
@@ -301,7 +317,7 @@ The retry policy is not called:
301
317
* for the last eligible upstream;
302
318
* when the request context is canceled or its deadline is exceeded.
303
319
304
-
Because HTTP statuses other than `429`, `502`, `503`, and `504` are treated as success from rcpx's perspective, `RetryPolicy` cannot make additional HTTP status codes, such as `500`, retryable under the current design.
320
+
`RetryPolicy` cannot make a non-retryable HTTP status retryable by itself, because the policy is only called after rcpx has already classified an attempt as non-success. To make an additional HTTP status such as `500` retryable, configure `AdditionalRetryableStatusCodes`.
305
321
306
322
`RetryPolicy` receives `AttemptOutcome`; it cannot inspect response bodies or response headers. It can decide whether rcpx should continue after an already-classified non-success attempt, but it is not a general response validation hook.
0 commit comments