xitrum-framework / xitrum

Async and clustered Scala web framework and HTTP(S) server
http://xitrum-framework.github.io/
MIT License
446 stars 52 forks source link

xitrum.Server.stop should wait until Xitrum is stopped #651

Closed ngocdaothanh closed 7 years ago

ngocdaothanh commented 7 years ago

Currently xitrum.Server.stop doesn't wait for the servers to be actually stopped, and it returns void.

It's impossible for the caller to know when Xitrum will stop.


Workaround:

When starting Xitrum, remember the EventLoopGroup of the HTTP and/or HTTPS servers that Xitrum starts:

val eventLoopGroups = xitrum.Server.start()

Then, to stop Xitrum gracefully:

val futures = eventLoopGroups.map(_.shutdownGracefully())

Then, wait the the futures to complete:

futures.foreach(_.awaitUninterruptibly())

The above should not be called in Xitrum action thread to avoid deadlock.

ngocdaothanh commented 7 years ago

Added xitrum.Server.stopAtShutdown to register a JVM shutdown hook that calls [[stop]] to stop Xitrum gracefully.

After the hook has been registered, you can stop Xitrum gracefully by running OS command:

kill <Xitrum PID>