Akka: handleErrors gets executed every 60 seconds? onComplete or error thrown?

akka
scala

(Fabian Schuessler) #1

Hello everyone,

I inherited some Akka code and fail to understand why the handleErrors function is executed again after 60 seconds after it already got executed once. This means that also the get function is executed again. I don’t even know where the 60 seconds come from, because none of the timeouts equals 60 seconds. Is this some built in timeout which I can’t find anything about?
I also tried to change the else clause

complete(HttpEntity(ContentTypes.text/html(UTF-8), “<h1>Failure”))

But it seems like I have to return a “complete”, so I don’t know what to return to make the function wait for my results.

Summary: I want the “get” to wait for the calculations/results.json, maybe even ten minutes. How can I achieve this? I have no idea why the Main seems to get executed multiple times.

object Main extends App with FailFastCirceSupport with LazyLogging {
...

  val route: Route = {
...
    handleErrors {
      logger.debug(s"HANDLE ERRORS...")
      cors(corsSettings) {
        handleErrors {
          path("vibe") {
            logger.debug(s"GET...")
            get {
              withRequestTimeout(900.seconds, request => timeoutResponse) {
                parameters(
                  (
...
                  )) {
...
                  ) =>
                    logger.debug(s"ATTEMPT START... $lock")
                    if (!lock) {
                      lock = true
...
                      implicit val timeout: Timeout = Timeout(900.seconds)

                      val reducerIntermediateResult: Future[Promise[ReducerIntermediateResult]] =
                        ask(masterActor, MasterActions.Start).mapTo[Promise[ReducerIntermediateResult]]

                      onComplete(reducerIntermediateResult.flatMap(promise =>
                        promise.future.map { intermediateResult =>
...

                          ReducerResult(
...
                          )
                        })) { extraction =>
                        lock = false
                        logger.debug("EXTRACTION...")
                        extraction match {
                          case Success(result) =>
                            masterActor ! PoisonPill
                            complete(result.asJson)

                          case _ =>
                            masterActor ! PoisonPill
                            logger.debug(s"EXTRACTION COMPLETE HTTP FAILURE...")
                            complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Failure"))
                        }
                      }
                    } else {
                      logger.debug(s"COMPLETE HTTP FAILURE...")
                      complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Failure"))
                    }
                }
              }
            }
          }
        }
      }
    }
  }

Output after about one minute:


13:55:11.141 [VSystem-akka.actor.default-dispatcher-10] DEBUG vibes.Main$ - HANDLE ERRORS…
13:55:11.142 [VSystem-akka.actor.default-dispatcher-10] DEBUG vibes.Main$ - GET…
13:55:11.145 [VSystem-akka.actor.default-dispatcher-10] DEBUG vibes.Main$ - ATTEMPT START… true
13:55:11.147 [VSystem-akka.actor.default-dispatcher-10] DEBUG vibes.Main$ - COMPLETE HTTP FAILURE…

Complete source code available here:


(Fabian Schuessler) #2

I am still not sure what the reasons for this behaviour are. Maybe it is because an error is thrown somewhere in the handleError block, maybe it is because of onComplete… I have no idea.
Would appreciate any help.