[Golang] Graceful server shutdown (and restart?)

2,140 views
Skip to first unread message

Scott Devoid

unread,
Jan 6, 2016, 1:12:23 PM1/6/16
to grp...@googlegroups.com
I'm wondering if there is a way to gracefully shut down a gRPC server.
Server.Stop() [1] appears to immediately close all existing
connections. Aside from a few streaming file upload / download
operations, all of my RPC handler functions set internal deadlines via
[2] so I'd like to see those complete successfully. Am I just
misreading Stop() or is there no way to stop accepting connections and
allow the server to drain gracefully before returning?

My second question: given a running Server with a registered service
X, is it possible to bind a different instance of service X to the
server? [3] Or should I call Server.Stop() then create a new server
and register the new instance to that one? Do I need to close and
reopen the listener?

The background here is that I have a "degraded" mode for my service
and it is easier to implement this as a completely different gRPC
server. However I would like to make handoff between the two modes as
clean as possible.

Thanks for your help!
~ Scott

[1]: https://godoc.org/google.golang.org/grpc#Server.Stop
[2]: https://godoc.org/golang.org/x/net/context#WithDeadline
[3]: https://godoc.org/google.golang.org/grpc#Server.RegisterService

Qi Zhao

unread,
Jan 6, 2016, 1:35:54 PM1/6/16
to Scott Devoid, grp...@googlegroups.com
On Wed, Jan 6, 2016 at 10:12 AM, Scott Devoid <sde...@gmail.com> wrote:
I'm wondering if there is a way to gracefully shut down a gRPC server.
Server.Stop() [1] appears to immediately close all existing
connections. Aside from a few streaming file upload / download
operations, all of my RPC handler functions set internal deadlines via
[2] so I'd like to see those complete successfully. Am I just
misreading Stop() or is there no way to stop accepting connections and
allow the server to drain gracefully before returning?
The pending issue: https://github.com/grpc/grpc-go/issues/147. We are going to touch it shortly. 

My second question: given a running Server with a registered service
X, is it possible to bind a different instance of service X to the
server? [3] Or should I call Server.Stop() then create a new server
and register the new instance to that one? Do I need to close and
reopen the listener?
Do you mean you want to use the new X to replace the old one? If yes, you need to stop the server and restart. 

The background here is that I have a "degraded" mode for my service
and it is easier to implement this as a completely different gRPC
server. However I would like to make handoff between the two modes as
clean as possible.

Thanks for your help!
~ Scott

[1]: https://godoc.org/google.golang.org/grpc#Server.Stop
[2]: https://godoc.org/golang.org/x/net/context#WithDeadline
[3]: https://godoc.org/google.golang.org/grpc#Server.RegisterService

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/CAJrQjStnNmRBP5bw2Bm5yOw8844Dsb17%3DtiDnWh-e5EKge9GNQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks,
-Qi
Reply all
Reply to author
Forward
0 new messages