Timeout and Fallback Policies
Bound waits and provide graceful fallbacks.
Why Timeouts Matter
A call that never returns is worse than one that fails: it ties up threads and connections. A timeout strategy caps how long an operation may run before Polly cancels it.
Adding A Timeout
Polly v8 provides AddTimeout. When the limit is exceeded it throws a TimeoutRejectedException and cancels the underlying token.
using Polly.Timeout;
var pipeline = new ResiliencePipelineBuilder()
.AddTimeout(TimeSpan.FromSeconds(3))
.Build();All lessons in this course
- Retry Policies
- Circuit Breaker Pattern
- Timeout and Fallback Policies
- Resilience Pipelines