# Akka RetryFlow.withBackoff does not guarantee maxRetry attempt

**URL:** <https://discuss.akka.io/t/akka-retryflow-withbackoff-does-not-guarantee-maxretry-attempt/5813>\
**Category:** Akka Streams & Alpakka\
**Tags:** streams\
**Created:** [January 28, 2020, 9:22am UTC](https://discuss.akka.io/t/akka-retryflow-withbackoff-does-not-guarantee-maxretry-attempt/5813 "2020-01-28T09:22:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![surendheran](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@surendheran](https://discuss.akka.io/u/surendheran)\
**Post date:** [January 28, 2020, 9:22am UTC](https://discuss.akka.io/t/akka-retryflow-withbackoff-does-not-guarantee-maxretry-attempt/5813/1 "2020-01-28T09:22:39Z")

</div>

I have a scenario to retry for some configured number whenever a stream ends with internal exception. To achieve this I tried RetryFlow.withBackoff functionality in Java. This triggers same source whenever decideRetry function returns other than Optional.empty(). But it’s retrying continuously even after the maxRetry threshold.

```auto
final Duration minBackoff = Duration.ofMillis(1000);
final Duration maxBackoff = Duration.ofMillis(1000);
final double randomFactor = 0d;
final int maxRetries = 2;

RetryFlow.withBackoff(
                        minBackoff,
                        maxBackoff,
                        randomFactor,
                        maxRetries,
                        flow,
                        (in, out) -> {
                            if(in.first() > 5 && in.second() > 0){
                                return Optional.of(Pair.create(in.first(), in.second()-1));
                            }
                            return Optional.empty();
                        });

```

Is there any workaround to control the retry flow on threshold limit?

---

<div class="post-metadata">

**Author:** ![ennru](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/ennru/32/1495_2.png) [@ennru](https://discuss.akka.io/u/ennru)\
**Post date:** [January 28, 2020, 11:59am UTC](https://discuss.akka.io/t/akka-retryflow-withbackoff-does-not-guarantee-maxretry-attempt/5813/2 "2020-01-28T11:59:39Z")

</div>

Hi Surendheran,

You hit [issue #28425](https://github.com/akka/akka/issues/28425) that is fixed in the upcoming Akka 2.6.3 release which will be published today. (It is fixed in 2.6.2, but we do not recommend using that release for a different reson.)

Regards,  
Enno.

---

<div class="post-metadata">

**Author:** ![surendheran](https://avatars.discourse-cdn.com/v4/letter/s/aeb1de/32.png) [@surendheran](https://discuss.akka.io/u/surendheran)\
**Post date:** [January 30, 2020, 6:46am UTC](https://discuss.akka.io/t/akka-retryflow-withbackoff-does-not-guarantee-maxretry-attempt/5813/3 "2020-01-30T06:46:09Z")

</div>

Thank you 😃
