Repository navigation
Fix #15368 - HTTP/2 client aborts a fully-received response during graceful shutdown - #15435
serhiy-bzhezytskyy wants to merge 3 commits into
Conversation
…ng graceful shutdown HttpConnectionOverHTTP2.ensureClosedOrAbortActiveChannels() aborts every active channel unconditionally on connection close. When a connection is closed at the end of a server graceful shutdown (GOAWAY), a channel whose response has been fully received but not yet consumed by the application is still active, so it gets aborted and the already-received response is discarded with a ClosedChannelException. Skip aborting a channel whose last DATA frame has already been received (HttpChannelOverHTTP2.isLastDataReceived()); such a response is complete and must be delivered to the application. Requests still in flight are aborted as before. Regression from the abort-on-close change; reproduced independently from Apache Solr (TestGracefulJettyShutdown) on 12.1.10. Signed-off-by: serhiy-bzhezytskyy <me@serhiy-bzhezytskyy.com>
|
The one red check is |
| // White-box reproduction of jetty#15368. The race is: the response has been fully received | ||
| // by the client transport (isResponseComplete() == true), but the exchange has not yet | ||
| // terminated (the application has not consumed the body), so the channel is still "active". | ||
| // If the connection is closed in this window (e.g. a GOAWAY at the end of a server graceful | ||
| // shutdown), the connection must NOT abort the exchange, otherwise the already-received | ||
| // response is discarded with a ClosedChannelException. | ||
| // | ||
| // To hit this window deterministically, we capture the HttpConnectionOverHTTP2 instance, let | ||
| // a small response be fully received (but not consumed), then invoke connection.close() |
There was a problem hiding this comment.
Please remove this comment as the git history should be all the context needed to dive back into this test.
|
|
||
| HTTP2CServerConnectionFactory h2c = new HTTP2CServerConnectionFactory(new HttpConfiguration()); | ||
| h2c.setInitialSessionRecvWindow(FlowControlStrategy.DEFAULT_WINDOW_SIZE); | ||
| h2c.setInitialStreamRecvWindow(FlowControlStrategy.DEFAULT_WINDOW_SIZE); |
There was a problem hiding this comment.
Is setting the receive windows necessary? What's the reason?
There was a problem hiding this comment.
Not necessary — removed. They were setting the windows back to the default (DEFAULT_WINDOW_SIZE), and the test still reproduces the race and passes without them.
| @Override | ||
| public boolean handle(Request request, org.eclipse.jetty.server.Response response, Callback callback) | ||
| { | ||
| response.setStatus(HttpStatus.OK_200); |
There was a problem hiding this comment.
200 OK is the default status, there is no need to repeat it.
|
|
||
| // The already-received response must still be deliverable. | ||
| byte[] body = IO.readBytes(listener.getInputStream()); | ||
| assertEquals(payload.length, body.length); |
There was a problem hiding this comment.
You should assert that the array contents are equal too with assertArrayEquals(payload, body).
- Remove the explanatory comment block (git history carries the context). - Drop the redundant server recv-window settings (not needed to hit the race) and the explicit 200 status (it is the default). - Assert the full response body with assertArrayEquals. Signed-off-by: Serhiy Bzhezytskyy <me@serhiy-bzhezytskyy.com>
|
Thanks for the review! Addressed all four:
|
|
Hi Ludovic — I think I've addressed all four review comments (the extra comment block, the receive-window setting, the redundant |
|
@lorban I have reservations about this change. The idea is that the method is supposed to really do a hard abort of all the streams, because we cannot wait forever that the application reads. I have to dig into the issue to be sure -- it might be that the change is correct, but we need to ensure that when we want to dispose all the streams, we do even if there is data to be read. |
Adds a no-leak assertion to the existing close() white-box test, and a companion test on the onFailure() path (HTTP2Session.onConnectionFailure -> connection.onFailure, which destroys without a trailing session.close()). Both assert the fully-received response is still delivered AND the pool ends leaked=0 with no lingering multiplexed connection. Both are non-vacuous: reverting the isLastDataReceived() gate makes each fail on the body read. Signed-off-by: serhiy-bzhezytskyy <me@serhiy-bzhezytskyy.com>
|
Thanks Ludovic and Simone. Simone — on the concern that we must still hard-abort/dispose the streams even when there is data to be read: I don't think this change weakens that. From Such a stream is already That's also why this doesn't diverge from the hard-abort path. // Since nothing else will arrive from the other peer, reset
// the streams for which the other peer did not send all frames.
Predicate<Stream> failIf = stream -> !((HTTP2Stream)stream).isLastDataReceived();so gating on I pushed If you'd rather gate it differently or see a hole in the |
|
@sbordet Gentle ping to ask for progress in reviewing/merging this. On the Solr side we're currently blocked from upgrading Jetty... |
|
@janhoy sorry for the delay, we've been busier that usual recently so work on this issue and the related ones was unfortunately put to the back burner. As a result, fixing this can't happen in the upcoming Jetty release that is due for the coming days. We want to fully review all issues related to #15368 and make sure this is all fixed once for good. Hopefully, this will happen before the next-next release; I've marked the issue as high-priority to make sure this won't escape our attention. We'll keep you posted as we progress on this. |
|
Superseded by #15628 |
Fixes #15368.
HttpConnectionOverHTTP2.ensureClosedOrAbortActiveChannels()aborts every active channel unconditionally when the connection is closed. When the connection closes at the end of a server graceful shutdown (GOAWAY), a channel whose response has been fully received but not yet consumed by the application is still active, so it gets aborted and the already-received response is discarded with aClosedChannelException.Fix: skip aborting a channel whose last DATA frame has already been received (
HttpChannelOverHTTP2.isLastDataReceived()) — that response is complete and must be delivered to the application. Requests still in flight are aborted as before, so the original intent of the abort-on-close change is preserved.Gating on
HttpExchange.isResponseComplete()does not work here, because HTTP/2 content is consumed lazily and the exchange is not marked COMPLETED until the application reads the body;isLastDataReceived()reflects that the response bytes have arrived off the wire.Test:
HttpClientTransportOverHTTP2Test.testConnectionCloseDoesNotAbortExchangeWithCompletedResponse— a white-box test that captures theHttpConnectionOverHTTP2, lets a response be fully received but not consumed, then callsconnection.close()directly (no socket-timing dependence). It fails withClosedChannelExceptionatensureClosedOrAbortActiveChannelswithout the fix and passes with it.GoAwayTestand the rest ofHttpClientTransportOverHTTP2Teststill pass.This was reproduced independently from the Apache Solr side (
TestGracefulJettyShutdown, ~60% failure on 12.1.10), as discussed in #15368.