RpcRetryInterceptor class
Interceptor that retries failed unary calls with backoff.
Only retries unary calls. Streaming calls pass through unchanged because replaying a stream is not generally safe.
Retries require an IDEMPOTENT method
The default predicate retries UNAVAILABLE, which is also the status a call
gets when the server processed it and the RESPONSE was lost. The two are
indistinguishable from the client, so a retry re-issues work that may already
have committed — and the caller cannot tell, because it is handed a success
either way. At maxAttempts: 3 one logical call can commit three times.
This is the standard gRPC retry trade-off rather than a quirk of this
implementation, but enabling it only where re-execution is safe is the
caller's job. Do not attach it to a charge, an append or a "send email"
unless the server deduplicates by request id — RpcContext carries
requestId for exactly that.
A server that pushes back names its own delay: an error carrying an
RpcRetryInfo with a positive retryDelay waits that long instead of
backoff, as gRPC clients do. A zero retryDelay (a capacity limit that
frees up by itself) waits backoff.
The wait never outlives the call's deadline: when the next delay would not fit in RpcContext.remainingTime, the retry is abandoned and the last error is rethrown immediately rather than after a sleep the caller did not budget for. A cancel cuts it short.
Usage:
caller.addInterceptor(RpcRetryInterceptor(
maxAttempts: 3,
backoff: RpcExponentialBackoff(baseDelay: Duration(milliseconds: 200)),
));
- Inheritance
-
- Object
- IRpcInterceptor
- RpcRetryInterceptor
Constructors
- RpcRetryInterceptor({int maxAttempts = 3, RpcBackoffPolicy backoff = const RpcExponentialBackoff(baseDelay: Duration(milliseconds: 200), maxDelay: Duration(seconds: 5)), RpcRetryPredicate? retryOn})
- Creates a retry interceptor.
Properties
- backoff → RpcBackoffPolicy
-
Backoff strategy for computing delays between retries.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxAttempts → int
-
Maximum number of attempts (including the initial call).
final
- retryOn → RpcRetryPredicate?
-
Predicate to decide if an error is retryable.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
check(
RpcCallInfo call) → FutureOr< void> -
Runs before this interceptor's method for unary, server-stream,
client-stream and bidirectional calls alike.
inherited
-
interceptBidirectionalStream<
TRequest, TResponse> (RpcCallInfo call, Stream< TRequest> requests, RpcBidirectionalStreamNext<TRequest, TResponse> next) → FutureOr<Stream< TResponse> > -
Bidirectional-stream call interceptor.
inherited
-
interceptClientStream<
TRequest, TResponse> (RpcCallInfo call, Stream< TRequest> requests, RpcClientStreamNext<TRequest, TResponse> next) → Future<TResponse> -
Client-stream call interceptor.
inherited
-
interceptServerStream<
TRequest, TResponse> (RpcCallInfo call, TRequest request, RpcServerStreamNext< TRequest, TResponse> next) → FutureOr<Stream< TResponse> > -
Server-stream call interceptor.
inherited
-
interceptUnary<
TRequest, TResponse> (RpcCallInfo call, TRequest request, RpcUnaryNext< TRequest, TResponse> next) → Future<TResponse> -
Unary call interceptor.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited