Gracefully shutdown example servers#6512
Conversation
ejona86
left a comment
There was a problem hiding this comment.
Hmmm... something else is going on. The blockUntilShutdown() in the main() should be enough...
| @@ -104,8 +104,8 @@ public List<ServerServiceDefinition> getMutableServices() { | |||
|
|
|||
| /** | |||
| * Initiates an orderly shutdown in which preexisting calls continue but new calls are rejected. | |||
There was a problem hiding this comment.
I think "initiates" is the key word here.
I think this would probably go better as a second paragraph that is merely informative. Something like:
Note that this method does not wait for the server to stop, so existing calls may continue after returning. To stop existing calls use {
@link#shutdownNow()} and to wait for the server to fully stop use {@link#awaitTermination()}.
There was a problem hiding this comment.
Combined your and @sanjaypujare's suggestions: af9a157
| * After this call returns, this server has released the listening socket(s) and may be reused by | ||
| * another server. | ||
| * This call will not wait for preexisting calls finish before returning. After this call returns, | ||
| * this server has released the listening socket(s) and may be reused by another server. |
There was a problem hiding this comment.
I suggest the following:
Initiates an orderly shutdown to allow preexisting calls to continue but new calls are
rejected. {@link #awaitTermination()} or {@link #awaitTermination(long, TimeUnit)} needs
to be called to wait for existing calls to finish. After this call returns, this server
has released the listening socket(s) and may be reused by another server.
|
Thanks for taking a look @ejona86!
From my understanding, the When the JVM is instructed to shutdown (such as via a SIGINT), it will call all registered shutdown handlers that are registered via Once all those For this reason, it is important for the shutdown hook's |
When you press control-C, it invokes the shutdown-hook. So |
That's not true. On ctrl-c, the JVM simply calls |
|
I'm going to move the conversation back to issue #6511. |
ejona86
left a comment
There was a problem hiding this comment.
The new documentation looks good to me. I want to hold off on adding the awaitTerminations until we gain a bit better understanding what is going on.
| * After this call returns, this server has released the listening socket(s) and may be reused by | ||
| * another server. | ||
| * | ||
| * Note that this method will not wait for preexisting calls finish before returning. |
There was a problem hiding this comment.
preexisting calls finish => preexisting calls to finish
af9a157 to
3328bfc
Compare
ejona86
left a comment
There was a problem hiding this comment.
Okay. So I was wrong, we do need the hook to wait until the server is done.
3328bfc to
7bd69d3
Compare
ejona86
left a comment
There was a problem hiding this comment.
One small thing, otherwise looks good. Thank you!
| try { | ||
| CompressingHelloWorldServerAllMethods.this.stop(); | ||
| } catch (InterruptedException e) { | ||
| e.printStackTrace(); |
There was a problem hiding this comment.
Couple of comments:
-
do you want to print to stderr in keeping with lines 65 and 71?
e.printStackTrace(System.err) -
do you want to mention/comment saying this is because the logger is closed as part of shutdown?
and of course make this change everywhere.
There was a problem hiding this comment.
do you want to print to stderr in keeping with lines 65 and 71?
e.printStackTrace(System.err)
Done in d997e5b
I also went ahead and fixed the call to logger in ManualFlowControlServer: 1df260a
do you want to mention/comment saying this is because the logger is closed as part of shutdown?
The call to System.err.println above already has this comment 😄
sanjaypujare
left a comment
There was a problem hiding this comment.
I have suggested a couple of changes.

The example servers do not properly wait until preexisting calls complete before shutting down (#6511).
This PR
awaitTerminationto wait for preexisting calls to complete (with a 30s timeout)Server.shutdownto clarify that the call does not wait for preexisting calls to complete before returning.