Skip to content

add timeout for closing connections at the graceful shutdown #1108

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

Merged
merged 7 commits into from
Feb 23, 2017

Conversation

deweerdt
Copy link
Member

On graceful shutdown, after the second GOAWAY message has been written,
it should be possible for use to safely close the connection, without
necessarily waiting for all streams to be processed.

On graceful shutdown, after the second GOAWAY message has been written,
it should be possible for use to safely close the connection, without
necessarily waiting for all streams to be processed.
@deweerdt
Copy link
Member Author

deweerdt commented Oct 20, 2016

Both the current behavior and what this PR suggests are within what the RFC permits, i think.

Maybe we need a config knob? One downside of the current behavior is that a never ending download might pin an H2O instance forever. Having the connection close makes server stops more predictable in terms of timing.

@kazuho
Copy link
Member

kazuho commented Oct 21, 2016

Thank you for the PR.

Even after the second GOAWAY, some responses might still be in-flight (the specification discuss the possibility of losing requests, not responses).

In such case, it would be desirable to postpone closing the connection until those responses finish. Otherwise, the clients would be left with partial responses, and since they are partial, they would never get retried.

So if this is an issue, I would suggest adding a timer that starts after sending the second GOAWAY and wait until then, or, add a function to server-starter (assuming that you use it to control H2O) that sends SIGKILL when the server fails to stop after some time after SIGTERM has been delivered.

This gives extra time to clients after we've sent the second GOAWAY
frame.
@deweerdt deweerdt force-pushed the close-connections-on-graceful-shutdown branch from 78f7a6b to 00126d7 Compare October 27, 2016 15:36
@deweerdt
Copy link
Member Author

@kazuho, thanks for your comments, I've implemented your suggestion to have a second timer in 00126d7. I believe that would be easier to troubleshoot in the long run, being a bit more predictable in behavior.

@kazuho
Copy link
Member

kazuho commented Oct 28, 2016

@deweerdt Thank you for the update!

I believe that would be easier to troubleshoot in the long run, being a bit more predictable in behavior.

Sounds reasonable.

The PR looks good to me; the only thing I'm a bit worried is that just waiting for one second might not be enough (for example for servers serving large files). Could we make it a configuration variable?

configure how long H2O should wait for connections to close when doing a
graceful shutdown
@deweerdt
Copy link
Member Author

@kazuho, thank you for your feedback. I've added a config item to make the timeout configurable in 7429037. It defaults to 0 which makes it inactive (H2O behaves as it used to).

@kazuho
Copy link
Member

kazuho commented Nov 7, 2016

(just in case you missed) CI seems to be failing due to t/00unit.libuv.t receiving a SIGSEGV:

�[31mt/00unit.libuv.t                                   (Wstat: 139 Tests: 22 Failed: 0)�[0m
�[31m  Non-zero wait status: 139�[0m

in libuv because the lib would still reference a free'd context.
@deweerdt
Copy link
Member Author

deweerdt commented Nov 7, 2016

@kazuho I had missed it, thanks for pointing this out. I've added the missing h2o_timeout_dispose call in fe0931f.

Copy link
Member

@kazuho kazuho left a comment

Choose a reason for hiding this comment

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

Thank you for the update. I'm glad to see the CI passing now.

Re-reading the PR, I have one concern. Please let me know what you think.

for (node = ctx->http2._conns.next; node != &ctx->http2._conns; node = next) {
h2o_http2_conn_t *conn = H2O_STRUCT_FROM_MEMBER(h2o_http2_conn_t, _conns, node);
next = node->next;
if (conn->state < H2O_HTTP2_CONN_STATE_IS_CLOSING) {
Copy link
Member

Choose a reason for hiding this comment

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

This if would mean that if there is a pending write, then closing the socket (and therefore the exit of the server) will be deferred until the write completes.

Is this what we intend, or should we better close a socket with a pending write immediately as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

That was indeed my intention, but my assumption was that this would happen relatively fast (next scheduler round), could it be delayed much longer?

Copy link
Member

Choose a reason for hiding this comment

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

If there is a pending write and the client never sends ACKs, then the write would stall for fairly long time without the write completion callback getting called. Eventually the idle timeout will kick in, but until then, I believe that the connection would be kept open.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I see. Fixing this. Thanks!

@deweerdt deweerdt force-pushed the close-connections-on-graceful-shutdown branch 3 times, most recently from de7aaf9 to 81cd064 Compare November 30, 2016 18:47
@deweerdt deweerdt force-pushed the close-connections-on-graceful-shutdown branch from 81cd064 to d5198ac Compare November 30, 2016 18:48
@deweerdt
Copy link
Member Author

@kazuho I believe d5198ac has all suggested changes, plus test coverage

@kazuho kazuho changed the title Close the connection at the end of the graceful shutdown add timeout for closing connections at the graceful shutdown Feb 23, 2017
@kazuho kazuho merged commit 80d3595 into h2o:master Feb 23, 2017
@kazuho
Copy link
Member

kazuho commented Feb 23, 2017

Thank you for the changes. Merged to master.

kazuho added a commit that referenced this pull request Feb 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants