Shutdown of Individual Services

60 views
Skip to first unread message

Rama Rao

unread,
Nov 23, 2017, 1:41:36 AM11/23/17
to grpc.io
I am using grpc-java. Let us say I have created a Service (ServiceImpl), added few services and started the service. 

Now if I want to graceful shutdown, do I  have first call shutdown on each of the services added to ServiceImpl and then follow-it with a call to service.shutdown?
or service.shutdown will handle both the cases?

Thanks,

Eric Anderson

unread,
Dec 7, 2017, 3:45:03 PM12/7/17
to Rama Rao, grpc.io
On Thu, Nov 23, 2017 at 12:41 AM, Rama Rao <ramarao...@gmail.com> wrote:
Now if I want to graceful shutdown, do I  have first call shutdown on each of the services added to ServiceImpl and then follow-it with a call to service.shutdown?
or service.shutdown will handle both the cases?

There isn't a `service.shutdown()`, just server (unless you made it, and then I won't know what it does). I think you should do things in the opposite order: first shut down the server, then the services.

I'd expect the normal flow to be:

server.shutdown(); // This simply prevents new RPCs
server.awaitTermination(5, SECONDS); // This is the grace time
server.shutdownNow(); // This kills all RPCs
// This needs some time to queue cancellation notifications.
// Note that terminated does not imply the application is done processing.
// It only means the server won't issue any more work to the application.
if (!server.awaitTermination(1, SECONDS)) {
  log.log(WARNING, "For some reason the server didn't shutdown promptly");
}
// After the server is terminated, all work has at least been queued onto the server's executor.
// You can shutdown and wait on that executor if you want. You can then also clean up services.
cleanUpServices();

Rama Rao

unread,
Dec 7, 2017, 4:02:21 PM12/7/17
to Eric Anderson, grpc.io
Thanks, Yeah, my main question was around whether server,shutdown can be called before we cleanup the services. Your answer helps.
Reply all
Reply to author
Forward
0 new messages