Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AskTimeoutException: on spray-can server stop

Tags:

scala

akka

spray

I am trying to stop spray-can web server with the following code:

implicit val timeout = Timeout(10 seconds)
val future = ask(IO(Http)(system), Http.Unbind(10 second))
Await.result(future, Duration.Inf)

but unfortunatelly I receive the following exception:

[error] AskTimeoutException: : Timed out (AskSupport.scala:334) [error] akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:334) [error] akka.actor.Scheduler$$anon$11.run(Scheduler.scala:118) [error] akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(Scheduler.scala:455) [error] akka.actor.LightArrayRevolverScheduler$$anon$12.executeBucket$1(Scheduler.scala:407) [error] akka.actor.LightArrayRevolverScheduler$$anon$12.nextTick(Scheduler.scala:411) [error] akka.actor.LightArrayRevolverScheduler$$anon$12.run(Scheduler.scala:363)

What am I doing wrong?

like image 442
Ivan Mushketyk Avatar asked Apr 01 '26 13:04

Ivan Mushketyk


1 Answers

The problem is you are sending the Http.Unbind message to the wrong actor (i.e. the manager actor for the IO extension - in this case, Http).

You have to send the Http.Unbind message to the HttpListener (this is the actor that replies to the Http.Bind message with an Http.Bound message). The following example sends Http.Bind to the manager actor and Http.Unbind to the HttpListener:

class TestActor extends Actor {
  override def preStart = {
    IO(Http) ! Http.Bind(self, interface = "localhost", port = 8080)
  }
  def receive = {
    case Http.Bound(_) => 
      println("bound")
      sender ! Http.Unbind(10 seconds)
    case Http.Unbound =>
      println("unbound")
      context.stop(self)
  }
}

More information can be found in the documentation section on starting and stopping.

like image 149
Christian Avatar answered Apr 04 '26 03:04

Christian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!