Skip to content

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

Description

@janhoy

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.write callback succeeds.
  • GracefulHandler correctly waits for the request and its stream wrapper to complete before the connector is stopped (verified with GracefulHandler debug logging: requestCount and streamWrapperCount reach 0 first).
  • A Jetty HttpClient over HttpClientTransportOverHTTP2 nevertheless fails the exchange with java.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.

Activity

  1. self-assigned this
    on Jul 6, 2026
  2. serhiy-bzhezytskyy commented on Jul 16, 2026

    @serhiy-bzhezytskyy

    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 TestGracefulJettyShutdown fails ~60% on current main with Jetty 12.1.10 (seed-deterministic), same ClosedChannelException. 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) — but HttpChannelOverHTTP2.isLastDataReceived() is the right signal:

    for (HttpChannelOverHTTP2 channel : channels)
    {
        HttpExchange exchange = channel.getHttpExchange();
        if (exchange != null && !channel.isLastDataReceived())
            exchange.getRequest().abort(failure);
    }

    Deterministic test: I wrote a white-box test in HttpClientTransportOverHTTP2Test that captures the HttpConnectionOverHTTP2, lets a response be fully received but unconsumed, then calls connection.close() directly — no socket-timing flakiness. It fails with ClosedChannelException at ensureClosedOrAbortActiveChannels without the fix and passes with it. GoAwayTest and the rest of HttpClientTransportOverHTTP2Test still 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.

  3. lorban commented on Jul 16, 2026

    @lorban
    Contributor

    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!

  4. serhiy-bzhezytskyy commented on Jul 16, 2026

    @serhiy-bzhezytskyy

    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.

  5. serhiy-bzhezytskyy commented on Jul 23, 2026

    @serhiy-bzhezytskyy

    While digging this one I found two related graceful-shutdown issues on the server side, now with fixes up:

    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.

  6. lorban commented on Jul 27, 2026

    @lorban
    Contributor

    @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.

  7. serhiy-bzhezytskyy commented on Jul 27, 2026

    @serhiy-bzhezytskyy

    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:

    • A protocol-free test for the connector contract: on unmodified jetty-12.1.x, Server.stop() shuts down a Graceful bean contained by a connector, but connector.shutdown() doesn't reach it (expected: <1> but was: <0>). No HTTP/2, no client — just a counter bean on a plain ServerConnector. 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.
    • A note that QuicheServerConnector already overrides shutdown() to call container.shutdown() before super.shutdown(), while AbstractHTTP2ServerConnectionFactory holds an equivalent SessionContainer that nothing invokes — so this may be less "add a feature" than "HTTP/2 is missing what QUIC already does."
    • Solr's TestGracefulJettyShutdown fails ~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.

  8. moved this to 🏗 In progress in FROZEN Jetty 12.1.13on Jul 29, 2026
  9. lorban commented on Aug 20, 2026

    @lorban
    Contributor

    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!

  10. lorban commented on Aug 20, 2026

    @lorban
    Contributor

    @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 by HttpClientTransportOverHTTP2 reacting to the lower-layer's zero-stream action is wrong. So your solution of discriminating the active channels based on the channel.isLastDataReceived() flag would break the expected behavior of an upper layer call to close().

    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.

  11. serhiy-bzhezytskyy commented on Aug 20, 2026

    @serhiy-bzhezytskyy

    @lorban wow, it's real good news! thanks a lot. i will test it ASAP

  12. serhiy-bzhezytskyy commented on Aug 20, 2026

    @serhiy-bzhezytskyy

    @lorban @janhoy Good news! the original issue is fixed by #15628, i have tested it. Thanks a lot!

  13. 4 remaining items

  14. moved this to 🏗 In progress in Jetty 12.1.14 FROZENon Aug 31, 2026
  15. moved this to 🏗 In progress in Jetty 12.0.40 FROZENon Aug 31, 2026
  16. janhoy commented on Sep 25, 2026

    @janhoy
    Author

    I commented on the PR, requesting status since this seems to have gone quite silent.

  17. added a commit that references this issue on Sep 29, 2026
    1f25119
  18. lorban commented on Sep 30, 2026

    @lorban
    Contributor

    @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.

  19. lorban commented on Sep 30, 2026

    @lorban
    Contributor

    Still needs to be backported to 12.0.x.

  20. reopened this on Sep 30, 2026
  21. added a commit that references this issue on Sep 30, 2026
    e7c0089
  22. added a commit that references this issue on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugHigh Priority

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions