The failsafe example in the docs doesn’t really wo...
# http4k
s
The failsafe example in the docs doesn’t really work. The circuitbreaker never triggers, it always continues to retry. You can see it if you add an
onRetry
block
Copy code
val failsafeExecutor = Failsafe.with(
            Fallback.of(Response(OK).body("Fallback")),
            RetryPolicy.builder<Response>()
                .withMaxAttempts(5)
                .handleResultIf { !it.status.successful }
                .onRetry { result ->
                    <http://logger.info|logger.info> { "${result.attemptCount} Retry is occurring ${result.isRetry}" }
                    <http://logger.info|logger.info> { "${result.lastResult} " }
                }
                .build(),
            CircuitBreaker.builder<Response>()
                .withFailureThreshold(1)
                .handleResultIf { it.status.serverError }
                .build(),
            Timeout.of(Duration.ofMillis(100))
        )
I’m pretty sure I’m not doing anything wrong here. I checked the failsafe docs and it says this is how it should work, but that the circuit breaker should stop the retries.
d
This is all down to failsafe - the filter is exceptionally simple 🙂 . Still - I've update the example to hopefully be a little easier to grok. If you comment out the last 2 policies you can see that the retry is working as intended (ie. only on >299). I suspect you were seeing weird interplay between the different policies.
s
Yes I know the retry is working properly, but according to failsafe’s docs, the circuit breaker should kill the retry (I mean, that’s the whole point of the circuit breaker right?)