⚙️ Fix gRPC Deadlines Ignored by a Retry Policy
A gRPC deadline, once set on a call, is an absolute point in time, not a per-attempt budget – and a Polly-based retry policy wrapped around a gRPC client call doesn’t automatically know that. If the same CallOptions.Deadline value is reused across every retry attempt, each retry still carries the original absolute deadline, so by the second or third attempt the deadline may already be almost spent, and the “retry” fails nearly instantly with DeadlineExceeded regardless of whether the server could have answered a fresh call just fine – the policy ends up spending the single remaining deadline budget faster instead of giving the call more real chances.
🔎 The Problem
var channel = GrpcChannel.ForAddress("https://backend:5001");
var client = new Greeter.GreeterClient(channel);
var policy = Policy
.Handle<RpcException>(e => e.StatusCode == StatusCode.Unavailable)
.WaitAndRetryAsync(3, attempt => TimeSpan.FromSeconds(attempt));
var deadline = DateTime.UtcNow.AddSeconds(5); // fixed, absolute deadline
await policy.ExecuteAsync(() =>
client.SayHelloAsync(request, deadline: deadline).ResponseAsync);
// Attempt 1 fails fast at t=0.2s (Unavailable)
// Policy waits 1s, retries at t=1.2s - deadline (t=5s) still fine
// Policy waits 2s, retries at t=4.3s after a slow attempt 2 -
// attempt 3 is called with the SAME deadline (t=5s), leaving well
// under a second of actual budget, so it fails as DeadlineExceeded
// almost immediately even though the server might have answered a
// fresh 5-second call just fine
✅ Fix: Give Each Attempt Its Own Deadline
- Compute a fresh per-attempt deadline inside the retry delegate, evaluated at call time rather than before the policy starts, if the intent is for each attempt to get its own full budget instead of sharing one absolute deadline across every retry.
- If the intent is genuinely that the whole operation, across all retries, must finish within a fixed window, keep the single absolute deadline but reduce the retry count or backoff delay so there’s realistically still time left for at least one more attempt by the time a retry fires.
- Log the remaining time until deadline at the start of each retry attempt during development, so a retry policy that’s silently starving itself shows up as a pattern in the logs instead of just looking like the backend is unreliable.
🚨 Why This Is Dangerous
A retry policy that’s supposed to improve reliability can end up making a struggling backend look completely broken instead – every retry attempt fails instantly with DeadlineExceeded, which reads exactly like the server itself is timing out, when the real cause is a client-side deadline that was already spent before the retry even started.
A gRPC deadline is a single countdown for the whole call, retries included – a retry policy that doesn’t know that is just spending the same shrinking budget faster.




