Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to keep running an akka-http server in production #1460

Open
richardimaoka opened this issue Oct 9, 2017 · 12 comments
Open

Document how to keep running an akka-http server in production #1460

richardimaoka opened this issue Oct 9, 2017 · 12 comments
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted help wanted Identifies issues that the core team will likely not have time to work on t:docs Issues related to the documentation

Comments

@richardimaoka
Copy link
Contributor

richardimaoka commented Oct 9, 2017

There was a feedback in Twitter.

https://twitter.com/brianclapper/status/917148072718798848

those past techniques aren’t working w/ this version of Akka HTTP. Documentation for non-toy cases would be awesome. ;-)

https://twitter.com/jlprat/status/917149279399108608

Agree, readLine is just for toy cases. iirc, HttpApp listens to SIGTERM as well as readLine. Thanks for the feedback about docs! 😊

Doc samples use readline to wait, which is not recommended in production.

@richardimaoka
Copy link
Contributor Author

Will work on it if no one else wants to pick this up in the next few days.

@bmc
Copy link

bmc commented Oct 9, 2017

FYI, since I'm the grumpy developer who lodged the complaint about the documentation :-/, what worked perfectly for me was one of these:

With HttpApp

Override waitForShutdownSignal() like this:

override protected def waitForShutdownSignal(system: ActorSystem)
                                            (implicit ec: ExecutionContext): Future[Done] = {
  Promise[Done].future
}

Rolling your own

Something like this:

val f = for { bindingFuture <- Http().bindAndHandle(routes, host, port)
              waitOnFuture  <- Promise[Done].future }
        yield waitOnFuture
sys.addShutdownHook { 
  // cleanup logic
}
Await.ready(f, Duration.Inf)

@ktoso
Copy link
Contributor

ktoso commented Oct 10, 2017

This should talk about coordinated shutdown https://doc.akka.io/docs/akka/current/scala/actors.html#coordinated-shutdown

Though we're missing that bit still in HTTP actually: #1210

So I propose to solve #1210 and then document things :)

@ktoso ktoso added 1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted t:docs Issues related to the documentation labels Oct 11, 2017
@LogicalTime
Copy link

I think just adding the documentation for creating a future that never completes would be very helpful in the short term. Having a future that never completes feels like I'm doing something wrong.

Also, I think the current default shutdown strategies have issues when using sbt-revolver. E.g. they start up and instantly shut down. Having a nice setup that works ok for production and with sbt-revolver would really help people get started fast.

Also a link to a page with other shutdown strategies would be excellent. For example with Tomcat, I believe you can shut down the server while not being the user that owns the process. I imagine a server could be shutdown via a config file changing, or a protected http endpoint being hit. Links to some strategies would really be nice.

@viktorklang
Copy link
Contributor

viktorklang commented Jan 3, 2018

Prefer Future.never over Promise[Done].future as the latter will leak callbacks.

@bmc
Copy link

bmc commented Jan 3, 2018

Wasn't aware that existed. (Clearly, I need to make a regular practice of reading the Scala API docs front to back.) Thanks, @viktorklang.

@viktorklang
Copy link
Contributor

@bmc You're most welcome, Brian! :)

@ktoso ktoso added the help wanted Identifies issues that the core team will likely not have time to work on label Jan 4, 2018
@git4skatz
Copy link

Could someone post a snippet of the proper way to block/suspend the main thread when using akka-http from Java?

@ktoso
Copy link
Contributor

ktoso commented Jan 24, 2018

It's shown in the above snippet already, please read this ticket

@git4skatz
Copy link

What's shown above appear to me to be Scala, not Java. Also, the documentation recommends against overriding HttpApp (solution shown above) in favor of using Http.BindandHandle. Additionally, as someone new to Akka and Akka-Http a solution give in context would be valuable.

@ktoso
Copy link
Contributor

ktoso commented Jan 24, 2018

Which is what this ticket is about... This ticket would be solved when we write this in the docs.
We'd welcome community help in adding this to the docs, as signaled by the "help wanted" tag.

In Java you get a CompletionStage so it's plain Java operations to await on it.

toCompletableFuture() + get()

https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html#toCompletableFuture--
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html

@bwbecker
Copy link

bwbecker commented Aug 9, 2022

I'm an Akka newbie looking at the documentation on https://doc.akka.io/docs/akka-http/current/introduction.html?language=scala#. Agreed that waiting for the user to hit enter on StdIn is not ideal and a pointer to better approaches would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - triaged Tickets that are safe to pick up for contributing in terms of likeliness of being accepted help wanted Identifies issues that the core team will likely not have time to work on t:docs Issues related to the documentation
Projects
None yet
Development

No branches or pull requests

7 participants