--- title: "ADR 0030: retryhttp retry policy for provider API clients" --- * Status: accepted * Code: [`pkg/provider/retryhttp/retryhttp.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/retryhttp/retryhttp.go) ## Context Git provider APIs rate-limit and fail transiently. A webhook handler or reconciler that blocks for minutes on a rate-limit reset, or replays a write twice, is worse than one that fails fast. ## Decision * Retries are bounded by `MaxAttempts` (initial request included) and every wait is capped at `MaxWait`. If a `Retry-After` or `X-RateLimit-Reset` value asks for longer than `MaxWait`, the transport returns the response as is instead of sleeping. * `429` is always retried. A `403` is retried only when it carries rate-limit headers (`Retry-After`, or `X-RateLimit-Remaining: 0`), because GitHub reports primary and secondary rate limits that way and a plain 403 is a permission error. * `5xx` other than `501`, and network errors, are retried only for `GET`, `HEAD`, `OPTIONS`, or a `POST` whose context was marked with `WithReadOnlyPostRetry`. In the network-error case the server may already have processed the request without the client seeing a response, so replaying a non-idempotent request could repeat its effect. Callers mark a POST only when it is read-only. * A request with a body is replayed only if `GetBody` is available; otherwise it is never retried. * Waits use jittered exponential backoff from `initialBackoff`, unless a header gives the delay. ## Consequences * Writes (`POST`, `PUT`, `PATCH`, `DELETE`) are retried only for rate limits, which by definition were not processed, not for server errors. * A reset further away than `MaxWait` surfaces as the original rate-limit response to the caller.