Polly
Polly copied to clipboard
WaitRetryForever is not working for a customexception in Polly.Net Resiliency
var waitAndRetryPolicy = Policy
.Handle<Exception>(e => e is MycustomException)
.WaitAndRetryForeverAsync(
attempt => TimeSpan.FromMilliseconds(500),
(exception, calculatedWaitDuration) =>
{
_logger.LogInfo(exception.GetType().FullName);
_logger.LogInfo(".Log,then retry: " + exception.Message);
});
var circuitBreakerPolicy = Policy
.Handle<Exception>()
.CircuitBreakerAsync(
4,
TimeSpan.FromSeconds(10),
(ex, breakDelay) =>
{
_logger.LogError(".Breaker logging: Breaking the circuit for " + breakDelay.TotalMilliseconds + "ms!");
},
() => { _logger.LogError(".Breaker logging: Call ok! Closed the circuit again!"); },
() =>
{
_logger.LogError(".Breaker logging: Half-open: Next call is a trial!");
}
);
return waitAndRetryPolicy.WrapAsync(circuitBreakerPolicy);
if i use my custom exception, My retry fails after logging .Breaker logging: Breaking the circuit for 10000ms!
It works fine if i use the ;default exception retry works after circuitbreak till it is closed
var waitAndRetryPolicy = Policy
.Handle<Exception>()
.WaitAndRetryForeverAsync(
attempt => TimeSpan.FromMilliseconds(500),
(exception, calculatedWaitDuration) =>
{
_logger.LogInfo(exception.GetType().FullName);
_logger.LogInfo(".Log,then retry: " + exception.Message);
});