-
Notifications
You must be signed in to change notification settings - Fork 596
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Provide Coordinated Shutdown for Akka HTTP #1210
Comments
I just checked, it seems that indeed we never got to adding http to the phases of coordinated shutdown. So here we need to actually do that, and then document using coordinated shutdown with akka http :) Somewhat related #188 |
Updating the ticket then. |
@jlprat @ktoso What the status of this task? Is there a workaround for this solution? As I understand from a bunch of opened and closed tickets
|
The status is as you see ;-) There's no hidden magical communication channels. It's the wrong phase I think, rather this should be in:
as documented. Would you like to take a stab at this issue and submit a PR? |
@ktoso I would like to do it, but I have a question. |
Also related with #907 |
|
Note that it should be possible to opt out of this, since specific applications may have other needs (for example keep the HTTP server alive and respond after leaving the cluster) |
Also related: #59 |
+1 with a preference for |
Really late to the party,. just noticed #2072 😅 |
Right though that's different @ignasi35 -- that's something you can opt in and call it. And currently there is even a large "TODO" in the docs about this ticket: https://github.com/akka/akka-http/pull/2072/files#diff-3f0330cd4e8b60684df0fcf735b85c78R67 That is "termination" which is a feature that you can trigger, and in this ticket we're talking about more docs or providing default Coordinated Shutdown. Even if it is about deciding that we don't enable by default. Could you explain in more depth why you think in a pure akka-http app it should not register this? |
If Akka-HTTP registers tasks into Coordinated Shutdown it will need to provide a means to disable them using a conf setting or something (as mentioned above). I find this default to be counter-intuitive. I think Akka should provide the tools and the docs recommending how to use them. Play and Lagom, OTOH, try to hide all the machinery and provide default setups that are reasonable enough. I that case I do think registering tasks by default is the right approach.
Oh, I see the difference now. 🤦♂️ Then, I think this issue should only document how to connect the graceful termination with Coordinated Shutdown and maybe include some recommendations on when and when not to do it? IIUC, at the moment it's possible to close akka HTTP using I'm still not 100% decided what the best option is but, ATM, I think |
If |
I think in order to properly support Coordinated Shutdown we need to modify or supplement Would it be possible to expose the Maybe we should even rename |
@hseeberger So it doesn't really matter if So this is the way I'm doing coordinated shutdown: val shutdown = CoordinatedShutdown(system)
shutdown.addTask(CoordinatedShutdown.PhaseServiceUnbind, "http-unbind") { () =>
binding.unbind().map(_ => Done)
}
shutdown.addTask(CoordinatedShutdown.PhaseServiceRequestsDone, "http-graceful-terminate") { () =>
binding.terminate(10.seconds).map(_ => Done)
}
shutdown.addTask(CoordinatedShutdown.PhaseServiceStop, "http-shutdown") { () =>
Http().shutdownAllConnectionPools().map(_ => Done)
} Not sure how necessary the last task is - they'll be cleaned up anyway when the actor system terminates. |
@jroper thanks. I had already figured out that unbind is idempotent and I'm shutting down exactly like you have shown ;-) |
@jroper I've implemented a graceful shutdown similar to how you've demonstrated, however I'm seeing that chunked responses are being munged and return garbage even if the service is just returning a small bit of json that definitely could be returned within the termination hard deadline. have you seen or dealt with this issue? |
@cyburgee If you don't mind temporary hacks you could add an
And in the conf:
This will unbind the port and then enforce a "minimum delay" so all in-flight responses can return normally if they return in less than 10s. The problems with this solution are that:
|
Instead of sleep you should use akka.pattern.after which already gives you a Future. |
Thank you! Edited. |
@cyburgee No, I haven't seen that, but I also haven't been using it in anger enough yet to see that. It sounds like what you're seeing is a bug. If you're able to reproduce, or can show more errors/interesting logs, it would be very helpful if you raised an issue about it. |
Related to playframework/playframework#9970 (Play |
I've opened #3142 which includes a simple way to add the recommended steps to Coordinated shutdown. |
With #3142 users can now add their server bindings to Akka Coordinated shutdown. |
I ran into this while using akka-grpc on k8s, which is still on akka-http 10.1.2 (before @ennru's fix above). If you're running in k8s, a simple solution is to follow @mikela's suggestion above, but set |
Thanks for the suggestion!
Note that it is also possible to run Akka gRPC with Akka HTTP 10.2.2 (because Akka HTTP 10.2.2 is binary compatible with 10.1.x). |
Make sure coordinated shutdown can be used in Akka HTTP, so pending requests can be processed before shutting the server down.
This idea originated as a comment from @raboof in #1207
Further info: http://doc.akka.io/docs/akka/current/scala/actors.html#coordinated-shutdown
Gitter Message
The text was updated successfully, but these errors were encountered: