Skip to content

refactor(tonic-xds): extract transport-agnostic RetryClassifier seam#2750

Open
LYZJU2019 wants to merge 1 commit into
grpc:masterfrom
LYZJU2019:lyzju2019/xds-retry-classifier-seam
Open

refactor(tonic-xds): extract transport-agnostic RetryClassifier seam#2750
LYZJU2019 wants to merge 1 commit into
grpc:masterfrom
LYZJU2019:lyzju2019/xds-retry-classifier-seam

Conversation

@LYZJU2019

@LYZJU2019 LYZJU2019 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactors the tonic-xds client retry layer to be transport-agnostic so non-gRPC transports (e.g. plain HTTP) can reuse the same retry engine without duplicating a retry state machine. This is a non-breaking, standalone change: all items stay crate-internal (pub(crate)) and the existing gRPC behavior is preserved.

Why

First step of generalizing the xDS retry layer so it can serve both gRPC and HTTP transports. Keeping the gRPC-specific logic (retryable codes + grpc-previous-rpc-attempts header) behind the classifier keeps tonic-xds transport-agnostic while leaving gRPC the default.

Testing

  • cargo build -p tonic-xds — clean (no warnings)
  • cargo test -p tonic-xds — 340 passed, 0 failed (incl. retry unit tests + test_retry_once_on_unavailable)
  • cargo clippy -p tonic-xds --all-targets — no new warnings in changed files
  • cargo doc -p tonic-xds --no-deps (with RUSTDOCFLAGS=-D warnings) — clean

Behavior is unchanged; the diff is behavior-preserving.

Split the retry layer into a transport-agnostic decision engine and a
transport-specific classifier so non-gRPC transports (e.g. plain HTTP)
can reuse the same retry machinery without duplicating a state machine.

- Add `RetryClassifier` trait: `is_retryable` decides retryability from
  the response/error; a default-noop `prepare_retry` allows per-retry
  request mutation.
- Add `GrpcRetryClassifier { retry_on }` implementing the previous gRPC
  behavior verbatim (retryable connection error or retryable grpc-status,
  plus stamping the `grpc-previous-rpc-attempts` header).
- Generalize `GrpcRetryPolicy` into `RetryPolicy<C>` holding the shared
  decision state (attempt cap, backoff, body cloning) behind `ArcSwap`
  and delegating transport decisions to the classifier. Tower's `Retry`
  service still owns the retry state machine.
- Rename `GrpcRetryPolicyConfig` -> `RetryConfig` (retry_on moved to the
  classifier) and `GrpcRetryBackoffConfig` -> `RetryBackoffConfig`.
- Keep `GrpcRetryPolicy = RetryPolicy<GrpcRetryClassifier>` as an alias
  so existing callers are unchanged.

Items remain crate-internal (`pub(crate)`); public re-exports are
deferred to the transport-API step. Behavior is unchanged.
@LYZJU2019
LYZJU2019 force-pushed the lyzju2019/xds-retry-classifier-seam branch from 5235089 to 79eeee0 Compare July 24, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant