# Akka Stream Backoff with WsClient timeout

**URL:** <https://discuss.akka.io/t/akka-stream-backoff-with-wsclient-timeout/6817>\
**Category:** Akka Libraries\
**Tags:** akka, scala\
**Created:** [July 2, 2020, 7:23am UTC](https://discuss.akka.io/t/akka-stream-backoff-with-wsclient-timeout/6817 "2020-07-02T07:23:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pujo9](https://avatars.discourse-cdn.com/v4/letter/p/cc9497/32.png) [@pujo9](https://discuss.akka.io/u/pujo9)\
**Post date:** [July 2, 2020, 7:23am UTC](https://discuss.akka.io/t/akka-stream-backoff-with-wsclient-timeout/6817/1 "2020-07-02T07:23:44Z")

</div>

currently, I want to wrap my WsClient inside a Akka backoff. for failure testing, we tried both Http 404 and timeout. when the error happened caused by Http 404, the backoff worked normally. But when it encountered a WsClient timeout, it keep restarting forever without any exponential backoff or maximum restart time. bellow is part of my code

```
RestartSource.onFailuresWithBackoff(
      minBackoff = 1 seconds,
      maxBackoff = 20 seconds,
      randomFactor = 1,
      maxRestarts = 10
    ) { () =>

      val futureResult: Future[Any] = myMethod()

      Source.future(futureResult)
        .map {
          case Failure =>
            throw new RuntimeException("testing BackOff")
          case Success =>
            log.info("FINISH")
          case _ => log.info("else")
        }
    }.runWith(Sink.head)
     .recoverWith {
        case _ =>
          log.info("exceed retries")
          )
     }.foreach(println)
	  

  private def myMethod(): Future[Any] = {

    val inquiryRequest = xxx

    wsClient.url(url)
      .withRequestTimeout(1 seconds)
      .post(Json.toJson(inquiryRequest).toString)
      .flatMap { pureResult =>
		Status.Success
      }.recover { e =>
      log.error("test")
      Status.Failure
    }
  }
```
