# RestartFlow eventually fails the stream?

**URL:** <https://discuss.akka.io/t/restartflow-eventually-fails-the-stream/6499>\
**Category:** Akka Streams & Alpakka\
**Created:** [May 14, 2020, 11:58am UTC](https://discuss.akka.io/t/restartflow-eventually-fails-the-stream/6499 "2020-05-14T11:58:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pawelkaczor](https://avatars.discourse-cdn.com/v4/letter/p/9dc877/32.png) [@pawelkaczor](https://discuss.akka.io/u/pawelkaczor)\
**Post date:** [May 14, 2020, 11:58am UTC](https://discuss.akka.io/t/restartflow-eventually-fails-the-stream/6499/1 "2020-05-14T11:58:18Z")

</div>

The following statement in scaladoc seems unclear to me. It does not give clear answer whether the stream will fail or not once the number of restarts reaches the maxRestarts value:

> <https://github.com/akka/akka/blob/v2.6.5/akka-stream/src/main/scala/akka/stream/scaladsl/RestartFlow.scala#L108>

> This [[Flow]] will not emit any failure. The failures by the wrapped [[Flow]] will be handled by restarting the wrapping [[Flow]] as long as maxRestarts is not reached.

Could someone confirm that the stream will fail? Thanks.

---

<div class="post-metadata">

**Author:** ![ignasi35](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/ignasi35/32/62_2.png) [@ignasi35](https://discuss.akka.io/u/ignasi35)\
**Post date:** [May 14, 2020, 2:00pm UTC](https://discuss.akka.io/t/restartflow-eventually-fails-the-stream/6499/2 "2020-05-14T14:00:33Z")

</div>

Hi @pawelkaczor,

the `Flow` will fail iff `maxRestarts` is a value greater or equal than zero and the number of consecutive restarts exceeds that value.

Cheers.

---

<div class="post-metadata">

**Author:** ![laszlovandenhoek](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/laszlovandenhoek/32/2009_2.png) [@laszlovandenhoek](https://discuss.akka.io/u/laszlovandenhoek)\
**Post date:** [September 2, 2020, 8:28am UTC](https://discuss.akka.io/t/restartflow-eventually-fails-the-stream/6499/3 "2020-09-02T08:28:23Z")

</div>

Looking at the code a bit more, I don’t see how this could ever trigger a failure:

```auto
  protected final def maxRestartsReached(): Boolean = {
    // Check if the last start attempt was more than the minimum backoff
    if (resetDeadline.isOverdue()) {
      log.debug("Last restart attempt was more than {} ago, resetting restart count", minBackoff)
      restartCount = 0
    }
    restartCount == maxRestarts
  }

  // Set a timer to restart after the calculated delay
  protected final def scheduleRestartTimer(): Unit = {
    val restartDelay = BackoffSupervisor.calculateDelay(restartCount, minBackoff, maxBackoff, randomFactor)
    log.debug("Restarting graph in {}", restartDelay)
    scheduleOnce("RestartTimer", restartDelay)
    restartCount += 1
    // And while we wait, we go into backoff mode
    backoff()
  }

  // Invoked when the backoff timer ticks
  override protected def onTimer(timerKey: Any) = {
    startGraph()
    resetDeadline = minBackoff.fromNow
  }

```

the reset deadline keeps being set to `minBackoff.fromNow` after each backoff, which obviously takes at least that long. That means that in `maxRestartsReached`, `resetDeadline.isOverdue()` is always `true` and the `restartCount` is always reset to 0.

Where’s the flaw in my logic? This seems consistent with what I’m observing, i.e. the flow is never interrupted if `maxRestarts > 0`.

---

<div class="post-metadata">

**Author:** ![laszlovandenhoek](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/laszlovandenhoek/32/2009_2.png) [@laszlovandenhoek](https://discuss.akka.io/u/laszlovandenhoek)\
**Post date:** [September 3, 2020, 9:24am UTC](https://discuss.akka.io/t/restartflow-eventually-fails-the-stream/6499/5 "2020-09-03T09:24:17Z")

</div>

Never mind, I found [Restart sources](https://discuss.akka.io/t/restart-sources/2592/4) where it is explained that `maxRestarts` only applies when the flow is first started. In my opinion, that makes the attribute **very** badly named. This merits a documentation change, IMO.
