Repository navigation
Description
Jetty version(s)
12.1.10 (regression from 12.1.9 — 12.1.9 does not exhibit the problem). Also reproduced on 12.0.36; 12.0.34 is not affected.
Jetty Environment
core
HTTP version
HTTP/2 (h2c)
Java version/vendor (use: java -version)
OpenJDK 21.0.7 (Temurin)
OS type/version
macOS 26 (also observed on Linux x86_64 CI runners)
Description
When a Server uses the graceful-shutdown wiring from the graceful module (GracefulHandler inserted at the root + Server.setStopTimeout(...)), and Server.stop() is initiated while an HTTP/2 (h2c) request is in flight, the client loses the response even though the server completes it correctly:
- The application's
Response.writecallback succeeds. GracefulHandlercorrectly waits for the request and its stream wrapper to complete before the connector is stopped (verified withGracefulHandlerdebug logging: requestCount and streamWrapperCount reach 0 first).- A Jetty
HttpClientoverHttpClientTransportOverHTTP2nevertheless fails the exchange withjava.nio.channels.ClosedChannelException.
This is ~100% reproducible with the standalone repro below (20/20 iterations on 12.1.10, 18/20 on 12.0.36; 0 failures on 12.1.9 and 12.0.34).
Two control experiments indicate the problem is on the client side:
- An HTTP/1.1 Jetty client against the same 12.1.10 server: 0/20 failures.
- An independent h2c client (
curl --http2-prior-knowledge, nghttp2) against the same 12.1.10 server performing the same graceful stop: receives the complete 256 KB response body with status 200, 5/5 iterations.
The regression window (12.1.9 → 12.1.10, 12.0.34 → 12.0.36) matches #15134 and its 12.0.x backport #14692 (fixes for #14654), which make HttpConnectionOverHTTP2 abort all active channels when the connection is closed. It appears this abort races with, and discards, a response that has already been fully sent by the server when the server closes the connection at the end of the graceful stop — failing exchanges that previously completed successfully.
AbstractConnector.setShutdownIdleTimeout(-1) has no effect on this behavior.
Found while upgrading Apache Solr from Jetty 12.0.34 to 12.1.10 (apache/solr#4574): Solr's TestGracefulJettyShutdown (a SolrJ client — Jetty HttpClient over h2c — querying a node while it stops gracefully) now fails in roughly half of CI runs, e.g. https://github.com/apache/solr/actions/runs/28686375015/job/85079758116, with the javabin response parser hitting a truncated body while the server logged the request as completed successfully.
How to reproduce?
Full standalone repro (plus the one-shot server used for the curl control): https://gist.github.com/janhoy/fdc807bd2436f0d1aa94de6a3fab80b9
GracefulRepro.java — per iteration: start a Server (h2c + HTTP/1.1 connector, GracefulHandler, stopTimeout=15000) with a handler that blocks until released; send one GET via HttpClient(HttpClientTransportOverHTTP2); once the handler has the request, call server.stop() on another thread and release the handler, which then writes a 256 KB response; assert the client receives status 200 and the full body.
javac -cp <jetty-jars> GracefulRepro.java
java -cp .:<jetty-jars> -Diters=20 GracefulRepro # h2c
java -cp .:<jetty-jars> -Diters=20 -Dhttp1=true GracefulRepro # HTTP/1.1 control
Results:
| Jetty | Protocol | Failed iterations |
|---|---|---|
| 12.0.34 | h2c | 0/50 |
| 12.1.9 | h2c | 0/20 |
| 12.0.36 | h2c | 18/20 (ClosedChannelException) |
| 12.1.10 | h2c | 20/20 (ClosedChannelException) |
| 12.1.10 | HTTP/1.1 | 0/20 |
curl control (server side: GracefulReproServer.java from the gist, which schedules server.stop() 200 ms after the request arrives and writes the response 300 ms later, while the graceful stop is waiting):
java -cp .:<jetty-12.1.10-jars> GracefulReproServer # prints PORT=<n>
curl -s --http2-prior-knowledge -o /dev/null -w "%{http_code} %{size_download}\n" http://127.0.0.1:<n>/test
# -> 200 262144, 5/5 iterations; server prints WRITE_OK each time
DISCLOSURE This issue report is compiled by an LLM, but only after thorough analysis of the test failures seen in Solr project.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields✅ Done
- StatusShow more project fields✅ Done
Activity
serhiy-bzhezytskyy commentedon Jul 16, 2026
I hit this from the Solr side too and dug into the root cause — sharing in case it helps, and I have a fix + test ready if you'd like a PR.
Reproduced independently: Solr's
TestGracefulJettyShutdownfails ~60% on current main with Jetty 12.1.10 (seed-deterministic), sameClosedChannelException. I also confirmed 12.1.11 does not fix it (bumped + reran, still fails).Root cause: the regression is commit
bf5e8a40de6("abort the active channel's request during close or failure").HttpConnectionOverHTTP2.ensureClosedOrAbortActiveChannels()aborts every active channel unconditionally. When a connection closes at the end of a 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, discarding a response the client already holds.Candidate fix: skip channels whose response is fully received. Gating on
HttpExchange.isResponseComplete()doesn't work (HTTP/2 content is consumed lazily, so the exchange isn't COMPLETED until the app reads it) — butHttpChannelOverHTTP2.isLastDataReceived()is the right signal:Deterministic test: I wrote a white-box test in
HttpClientTransportOverHTTP2Testthat captures theHttpConnectionOverHTTP2, lets a response be fully received but unconsumed, then callsconnection.close()directly — no socket-timing flakiness. It fails withClosedChannelExceptionatensureClosedOrAbortActiveChannelswithout the fix and passes with it.GoAwayTestand the rest ofHttpClientTransportOverHTTP2Teststill pass.Happy to open a PR with the fix + test if that's useful — didn't want to step on it since it's assigned to you.
lorban commentedon Jul 16, 2026
Sorry for the delay getting back to you on this issue.
If you can create a PR with a test and a fix, we would definitely consider it!
serhiy-bzhezytskyy commentedon Jul 16, 2026
Ludovic, thanks.
Opened #15435 with the fix and a test.
It gates the abort on HttpChannelOverHTTP2.isLastDataReceived(), as suggested above — a channel whose last DATA frame has already arrived is skipped, so a fully-received-but-unconsumed response is delivered rather than discarded; in-flight requests are still aborted. The test (HttpClientTransportOverHTTP2Test.testConnectionCloseDoesNotAbortExchangeWithCompletedResponse) captures the connection, receives a response without consuming it, then calls connection.close() directly — fails with ClosedChannelException without the fix, passes with it; GoAwayTest and the rest still pass.
serhiy-bzhezytskyy commentedon Jul 23, 2026
While digging this one I found two related graceful-shutdown issues on the server side, now with fixes up:
connector.shutdown()doesn't send a GOAWAY, so HTTP/2 keeps accepting new streams (PR Issue #13569 - connector.shutdown() gracefully closes HTTP/2 sessions #15472)connector.shutdown()future never completes ifstop()follows with an HTTP/2 client connected (PR Issue #13602 - complete pending shutdown() future on connector stop #15473)Together with this issue (#15368 / PR #15435, the client aborting an already-received response), they're the client and server sides of the same HTTP/2 graceful-shutdown behavior.
lorban commentedon Jul 27, 2026
@serhiy-bzhezytskyy it looks like the H2 shutdown mechanism is a bit in a sorry state at the moment. Sorry for this, and the delay getting to work on the problem.
We are going to take the time to carefully review these reported bugs, as we want to be certain that they get properly fixed once and for all.
Stay tuned.
serhiy-bzhezytskyy commentedon Jul 27, 2026
Thanks Ludovic — that's good to hear.
Three things I have on hand if any of them would save you time — say the word and I'll put them up, otherwise I'll leave you to it:
jetty-12.1.x,Server.stop()shuts down aGracefulbean contained by a connector, butconnector.shutdown()doesn't reach it (expected: <1> but was: <0>). No HTTP/2, no client — just a counter bean on a plainServerConnector. That's Graceful shutdown continues to allow new requests in HTTP/2 #13569 reduced to two assertions, and it should survive whichever design you choose.QuicheServerConnectoralready overridesshutdown()to callcontainer.shutdown()beforesuper.shutdown(), whileAbstractHTTP2ServerConnectionFactoryholds an equivalentSessionContainerthat nothing invokes — so this may be less "add a feature" than "HTTP/2 is missing what QUIC already does."TestGracefulJettyShutdownfails ~60% on Solr main against 12.1.10 (and 12.1.11), which is where I hit HTTP/2 client aborts exchange and loses response completed during server graceful shutdown (regression in 12.1.10 / 12.0.36 from #15134 / #14692) #15368 from. Once a candidate fix exists I can run it against that and report whether the downstream symptom clears.I hope that's a help rather than noise — let me know either way.
lorban commentedon Aug 20, 2026
For future references, here is the RCA of this problem:
client gets GO_AWAY graceful then GO_AWAY with stream id=1
-> preserves stream 1
client sends GO_AWAY with stream id=1 (0? double-check) once stream 1 got the frame with the last flag set to true,
see HTTP2Stream.readData() which calls session.removeStream() which triggers sending the GO_AWAY frame
-> closes the HttpConnectionOverHTTP2 that has stream 1 in its activeChannels set, aborts the latter.
the above makes HttpReceiver.abort() called, caused by closing the HttpChannelOverHttp2 before releasing it.
This would not happen if HttpChannelOverHttp2.release() was called before HttpConnectionOverHTTP2.close().
But HttpChannelOverHttp2.release() only gets called when HttpReceiver.responseSuccess() is called, which does
not happen before EOF is read from the Content.Source as HttpReceiverOverHttp2.read() forces the chunk's last flag
to false even when the data's last flag is set to true to force an extra read() call to read a synthetic EOF and
call HttpReceiver.responseSuccess() only then.
@serhiy-bzhezytskyy's analysis was right, except for how the H2 layers interact with each other. Very good work there!
lorban commentedon Aug 20, 2026
@serhiy-bzhezytskyy Good news! I finally managed to go down this rabbit hole and figured exactly how the different H2 layers where wrongly linked together.
In a nutshell, the
HttpConnectionOverHTTP2.close()call is meant to be called from a higher layer, to indiscriminately abort everything that is still active. The fact that it is also called byHttpClientTransportOverHTTP2reacting to the lower-layer's zero-stream action is wrong. So your solution of discriminating the active channels based on thechannel.isLastDataReceived()flag would break the expected behavior of an upper layer call toclose().I've created #15628 with a prototype fix as well as an adaptation of the test written by @janhoy from Apache Solr. I may still clean the implementation in one way or the other, but overall it should contain the proper fix in essence and solve the problem reported here.
@janhoy @serhiy-bzhezytskyy I'd be glad if you could both give it a try and report back if that PR actually solves the problem for you too.
Finally, thank you both for your patience waiting for us to react, and the quality of the work you've put into reporting and troubleshooting this issue. You both truly did great and deserve special thanks for that.
serhiy-bzhezytskyy commentedon Aug 20, 2026
@lorban wow, it's real good news! thanks a lot. i will test it ASAP
serhiy-bzhezytskyy commentedon Aug 20, 2026
@lorban @janhoy Good news! the original issue is fixed by #15628, i have tested it. Thanks a lot!
4 remaining items
janhoy commentedon Sep 25, 2026
I commented on the PR, requesting status since this seems to have gone quite silent.
Fixes #15368 - Fix incorrect eager aborting of H2 channels during gra…
lorban commentedon Sep 30, 2026
@janhoy good news: we managed to find some time to get the fix for this problem merged into 12.1.x, which means it's going to be part of the next version scheduled to be released in a few days.
Thanks for the reminder, and sorry to get you waiting for so long.
lorban commentedon Sep 30, 2026
Still needs to be backported to 12.0.x.
Fixes #15368 - Fix incorrect eager aborting of H2 channels during gra…
SOLR-18297: Upgrade Jetty to 12.1.14