Skip to content
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

okhttp: forceful close after MAX_CONNECTION_AGE_GRACE_TIME #9968

Merged
merged 5 commits into from Mar 27, 2023

Conversation

YifeiZhuang
Copy link
Contributor

fixes #9721

@@ -926,7 +935,7 @@ public void ping(boolean ack, int payload1, int payload2) {
return;
}
if (GRACEFUL_SHUTDOWN_PING == payload) {
triggerGracefulSecondGoaway();
triggerGracefulSecondGoaway(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually the primary flow. secondGoawayTimer is just in case the ping takes too long, we still want to continue the shutdown process. So using null here means that shutdown(void) is correct, but the max connection age won't have a grace time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right that's true.
So after the first goaway and ping, the secondGoawayTimer is set with 1s ping timeout.
A normal successful ping ack within 1s cancels the timer and trigger second goAway and graceful shutdown. No ping after 1s also triggers the same path.

The ping method does not take any more parameter, as it implements frame handler interface. So I made the grace time a field. And it is synchronized on the lock to allow read and write to be thread safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ejona86 wdyt?

@@ -289,6 +294,10 @@ private void triggerGracefulSecondGoaway() {
} else {
frameWriter.flush();
}
if (gracefulShutdownPeriod != null) {
forcefulCloseTimer = scheduledExecutorService.schedule(
this::triggerForcefulClose, gracefulShutdownPeriod, TimeUnit.NANOSECONDS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the behavior when someone is doing:

server.shutdown();
server.awaitTerminated(10000, TimeUnit.SECONDS);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention that #9649 changed the behavior of this. So I put it back.
So sound like we should do graceful shutdown when server.shutdown?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any change to triggerGracefulSecondGoaway() in #9649. We will do "double GOAWAY" graceful shutdown when server.shutdown(). That's what the code is doing already. server.shutdown() doesn't have a forceful close though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never mind about #9649.
I updated server.shutdown() to avoid forceful close.

@YifeiZhuang YifeiZhuang merged commit 046e02b into grpc:master Mar 27, 2023
5 checks passed
@YifeiZhuang YifeiZhuang deleted the okhttp-grace-shutdown branch March 27, 2023 22:31
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MAX_CONNECTION_AGE_GRACE not really implemented
2 participants