-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Gracefully shutdown example servers #6512
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
Gracefully shutdown example servers #6512
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... something else is going on. The blockUntilShutdown() in the main() should be enough...
@@ -104,8 +104,8 @@ public int getPort() { | |||
|
|||
/** | |||
* Initiates an orderly shutdown in which preexisting calls continue but new calls are rejected. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preexisting calls finish => preexisting calls to finish
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doh! Good catch
af9a157
to
3328bfc
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. So I was wrong, we do need the hook to wait until the server is done.
examples/src/main/java/io/grpc/examples/advanced/HelloJsonServer.java
Outdated
Show resolved
Hide resolved
examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java
Outdated
Show resolved
Hide resolved
examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java
Outdated
Show resolved
Hide resolved
examples/src/main/java/io/grpc/examples/helloworld/HelloWorldServer.java
Outdated
Show resolved
Hide resolved
3328bfc
to
7bd69d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small thing, otherwise looks good. Thank you!
examples/src/test/java/io/grpc/examples/routeguide/RouteGuideServerTest.java
Outdated
Show resolved
Hide resolved
try { | ||
CompressingHelloWorldServerAllMethods.this.stop(); | ||
} catch (InterruptedException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have suggested a couple of changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The example servers do not properly wait until preexisting calls complete before shutting down (#6511).
This PR
awaitTermination
to wait for preexisting calls to complete (with a 30s timeout)Server.shutdown
to clarify that the call does not wait for preexisting calls to complete before returning.