How to stop SimpleRoutingApp without getting an error

401 views
Skip to first unread message

Barry Kaplan

unread,
Nov 18, 2013, 10:22:46 PM11/18/13
to spray...@googlegroups.com
We are using SimpleRoutingApp, and when stopping the process we get an error logged:

2013-11-19 03:12:26,939 ERROR akka.io.TcpListener - Monitored actor [Actor[akka://vimana-rules/user/IO-HTTP/listener-0]] terminated | akkaSource=akka://vimana-rules/system/IO-TCP/selectors/$a/0, sourceThread=vimana-rules-akka.actor.default-dispatcher-5, tenant=tft, service=rules [vimana-rules-akka.actor.default-dispatcher-6] 
akka.actor.DeathPactException: Monitored actor [Actor[akka://vimana-rules/user/IO-HTTP/listener-0]] terminated
2

Is there any way to do a clean shutdown?

Johannes Rudolph

unread,
Nov 19, 2013, 8:20:37 AM11/19/13
to spray...@googlegroups.com
Hi Barry,
Which version are you running and how do you shutdown? If you don't
want to force shutdown you should try to run a termination sequence in
the reverse direction as the initialization sequence, i.e. in the case
of the HttpListener, you should send a `Http.Unbind` message to the
listener you created with `Http.Bind`. The listener ActorRef is the
sender of the `Http.Bound` message.

--
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net

Barry Kaplan

unread,
Nov 19, 2013, 12:23:22 PM11/19/13
to spray...@googlegroups.com, johannes...@googlemail.com
I am running 1.1-RC3

I have tried:

  io.IO(Http) ? Http.Unbind
  io.IO(Http) ? Http.CloseAll

But both result in 

akka.actor.DeathPactException: Monitored actor [Actor[akka://vimana-rules/user/restapi-tenant-router]] terminated
akka.actor.DeathPactException: Monitored actor [Actor[akka://vimana-rules/user/IO-HTTP/listener-0]] terminated

The actor system is shutdown immediately after the unbind or closeall. So maybe there is a race condition?

I based my code on Mathias' response in https://groups.google.com/forum/#!topic/spray-user/6Co2C9jSbAg.

Barry Kaplan

unread,
Nov 19, 2013, 12:34:04 PM11/19/13
to spray...@googlegroups.com, johannes...@googlemail.com
This "seems" to work:

  io.IO(Http) ? Http.Bind(router, hostname, port) onComplete {
    case Success(Http.Bound(endpoint)) =>
      log.info(s"Started REST API: uri=$endpoint/$basePath")
    case _ =>
      log.info(s"Failed to start REST API")
  }

  def stop() {
    Await.result(io.IO(Http) ? Http.CloseAll, Duration(15, "seconds")) 
    log.info(s"Stopped REST API")
    actorSystem.stop(io.IO(Http))
    actorSystem.stop(router)
  }

Mathias Doenitz

unread,
Nov 20, 2013, 7:54:52 AM11/20/13
to spray...@googlegroups.com
Barry,

yes, waiting for the ACK reply to your `Http.CloseAll` command before shutting down the actor system is the best approach.
Note that you can also do it in a non-blocking fashion (without the await) via an `onComplete` callback on the `IO(Http) ? Http.CloseAll` future…

Cheers,
Mathias

---
mat...@spray.io
http://spray.io
> --
> You received this message because you are subscribed to the Google Groups "spray-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

eec...@gmail.com

unread,
Dec 25, 2013, 5:35:08 PM12/25/13
to spray...@googlegroups.com
Combining the advise of Johannes and Mathias I came up with this approach: https://gist.github.com/EECOLOR/8127533

Johannes Rudolph

unread,
Dec 26, 2013, 5:32:24 AM12/26/13
to spray...@googlegroups.com
Thanks for sharing!
> "spray.io User List" group.
>
> To unsubscribe from this group and stop receiving emails from it, send an
> email to spray-user+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages