-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Graceful close of HTTP/2 Connection #2788
Comments
@gregw if If the server is shutting down, the HTTP/2 implementation stops all HTTP/2 sessions so that they queue a Other than implementing |
So I have changed the name of this issue. We probably need the ability to gracefully close a HTTP/2 connection (aka session). |
@gregw is this on the roadmap? do you have suggestions for implementation? |
@jjestrel we have not looked at it, it's more of a low priority feature request that is hard to implement, so little gain for big effort. @gregw I imagine a case where a browser will request a number of resources concurrently to render a page, and in only one of those requests it puts a In HTTP/2 the fact that one request has If it is the client initiating the close, I don't see why it cannot stop sending request on that connection and then close it. If it is the server initiating the close, then perhaps we could have some kind of gracefulness, but while we can reset new incoming requests, how long are we going to wait for requests that are being processed? That seems to be more of an application logic rather than a container logic. We could introduce a Jetty specific error code so that for a new request that is reset with this new error code the client will know that the server is closing the connection and won't issue other requests, but clients typically multiplex a batch of requests that have meaning together: what if some of them are processed and some are failed due to graceful close? Seems to me that the complication of handling well all cases is way larger than the small benefits that it brings - I could be convinced otherwise with a detailed use case. |
We are using h2 where few clients send many requests to the server. When we do a new deploy we try to gracefully shutdown the server but currently observe timeouts from the client side. We suspect it's because we don't stop accepting requests. I've confirmed StatisticsHandler is installed and the graceful shutdown code in there is getting run |
HTTP/2 intends for GOAWAY frames to be used for graceful shutdown.
But there’s a problem in HTTP2Session.java:
Shutting down the output stream prevents Jetty from shutting down gracefully! In particular, in-flight requests cannot be responded to. Similarly, inbound pings cannot be responded to. As soon as the output is shutdown the game is lost. |
@swankjesse so what if a in-flight request takes 20 minutes because it's stuck in a RDBMS query? The wish of "finish the processing of previously established streams" now requires a timeout - how long are you willing to wait for the streams to finish? I think this is an application behavior rather than a container behavior, as different applications may apply different logics. |
I completely agree that 20-minute calls need not be shut down gracefully. I’m working on a set of microservices that make lots of ~10 ms calls. Some constraints I’m trying to satisfy:
Abrupt HTTP/2 shutdowns mean that clients need to retry calls, which wrecks predictable latency. Graceful HTTP/2 shutdowns would allow servers to restart and redistribute load without any failed calls. |
@sbordet I disagree. If an application is taking 20 minutes to process a request, then it will take that 20 minutes regardless of if the output stream is open or we can actually use the results of those spent resources. I can't see how allowing an existing session to send a response after a GO_AWAY has been sent is a DOS vector at all. The server should be able to send a GO_AWAY, then new streams are ignored and existing streams left to complete. When the stream count goes to 0 the connection is closed. |
@sbordet let's hangout on this issue this week. |
Waiting on graceful shutdown in Jetty jetty/jetty.project#2788
Implemented HTTP2Session.shutdown() to shutdown the session gracefully with a timeout. It's a draft because there are a number of issues to be resolved. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Made HTTP2SessionContainer implement Graceful, so that it can be found in the component hierarchy and can shutdown all sessions. Modified HTTP2ServerSession to reject requests if already closed/shutdown. Implemented shutdown in HTTP2Session. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Updates after review. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
Updates after review. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
…2_close Fixes #2788 - Graceful close of HTTP/2 Connection.
The
Connection: close
header is not supported by the HTTP/2 protocol, so currently if it is set in a request or a response, it is simply not sent and ignored.However, adding
Connection: close
header to a response is used by Jetty and applications to indicate that the connection should be closed (due to errors, do to shutdown etc.)So should we also provide a mechanism that will note the
Connection:close
headers as they are stripped out and switch the h2 connection into a shutdown state, where it will go_away the next time the stream count reaches 0?Or should we provide some other shutdown mechanism?
The text was updated successfully, but these errors were encountered: