Repository navigation
Closed as not planned
Labels
BugFor general bugs on Jetty side
Description
Jetty version(s)
Jetty 12.1.1
Jetty Environment
ee10
Java version/vendor (use: java -version)
JDK 21
Description
When performing a graceful shutdown and using HTTP/2:
- New requests seem to continue being accepted on existing connections
- The graceful shutdown does not complete until the connections themselves timeout.
I was expecting this to have equivalent behaviour to HTTP/1
- New requests should be rejected
- The graceful shutdown should complete as soon as all active requests complete.
How to reproduce?
public static class Http2GracefulStopServer {
public static void main(String[] args) throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server, new HTTP2CServerConnectionFactory());
connector.setPort(0);
connector.setShutdownIdleTimeout(15_000);
server.setConnectors(new Connector[] {connector});
ServletContextHandler context = new ServletContextHandler();
CountDownLatch didRecvRequest = new CountDownLatch(1);
CountDownLatch shouldFinishResponse = new CountDownLatch(1);
context.addServlet(new HttpServlet() {
@SneakyThrows
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) {
log.info("Received request: {}", req);
didRecvRequest.countDown();
resp.getOutputStream().flush();
shouldFinishResponse.await();
}
}, "/*");
server.setHandler(context);
server.start();
String url = "http://localhost:%d/".formatted(connector.getLocalPort());
ClientConnector clientConnector = new ClientConnector();
HttpClient http2Client = new HttpClient(new HttpClientTransportDynamic(clientConnector, new ClientConnectionFactoryOverHTTP2.HTTP2(new HTTP2Client(clientConnector))));
http2Client.start();
http2Client.newRequest(url)
.method(HttpMethod.GET)
.send(resp -> log.info("First request finished {}", resp.getResponse().getStatus()));
didRecvRequest.await();
CompletableFuture<Void> shutdownCompleted = server.getConnectors()[0].shutdown();
// Why does this one succeed ???
http2Client.newRequest(url)
.method(HttpMethod.GET)
.send(resp -> log.info("Second request finished {}", resp.getResponse().getStatus()));
shouldFinishResponse.countDown();
Instant startTime = Instant.now();
shutdownCompleted.get();
// Why does this take 15 seconds / shutdownIdleTimeout ???
log.info("Shutdown completed after {}", Duration.between(startTime, Instant.now()));
}
}
Activity
jacob-pro commentedon Sep 11, 2025
I realise I had a few misunderstandings about the equivalent HTTP/1.1 behaviour; in my own HTTP/1.1 testing the request after
shutdown()fails because it is making a new connection, if I attempt to re-use an existing connection then it does succeed. However it also has aConnection: closeheader as per: #2749 preventing further requests.Adapting my HTTP/2 test above, though I can still send many requests after shutdown:
I found I was able to add a HTTP/2 customizer to create equivalent behaviour to the HTTP/1.1 case:
This then allows 1 more HTTP/2 request after shutdown, but prevents additional requests. I wonder though if there is a way to send the GOAWAY immediately at the point of
shutdown()?I found this PR which looks like it was supposed to implement GOAWAY on shutdown, I wonder if it is not working correctly @sbordet? #4554
serhiy-bzhezytskyy commentedon Jul 21, 2026
I ran into this while working on the related HTTP/2 graceful-shutdown bug #15368 (my fix: #15435) and dug into this one too. Root cause looks like:
connector.shutdown()stops the acceptors and reduces the endpoint idle timeouts, but it never reaches theSessionContainergraceful path added in #4554 — so live HTTP/2 sessions never get a GOAWAY, keep accepting new streams, and the shutdown only completes at the shutdown idle timeout (the 15s the reporter saw).Graceful.shutdown(connector)works because it traverses and findsSessionContainer; the directconnector.shutdown()call doesn't.That seems to violate the
Connector/Gracefulcontract ("should not accept any new load … completed once all load is completed"), so I put together a fix + a reproducing test:connector.shutdown()→ the client session never receives a GOAWAY.AbstractConnector.shutdown()also shut down its containedGracefulbeans (i.e.SessionContainer) — only the contained ones, since the connector is itselfGracefuland would otherwise recurse. Side-effect-only; I keptshutdown()'s completion semantics unchanged.One flag from my own testing: my first attempt also folded the graceful futures into the returned
CompletableFuture, which regressed HTTP/1.1 pipelining (ServerConnectorHttpServerTest.testShutdown). Keeping the return as-is and treating the graceful close as a pure side effect fixes this with the full jetty-server suite still green.Before I open a PR — is
AbstractConnectorthe right place, or would you prefer it elsewhere (or isGraceful.shutdown(connector)the intended API andconnector.shutdown()meant to be lighter)? Test + fix ready whenever. @sbordetserhiy-bzhezytskyy commentedon Jul 23, 2026
I ran into this while working on #15368 (the HTTP/2 client-side graceful-shutdown bug, #15435) and dug into this one too. Root cause:
AbstractConnector.shutdown()never reaches the HTTP/2SessionContainer's graceful path (from #4554), soconnector.shutdown()sends no GOAWAY and the session keeps accepting streams until the idle timeout — theGraceful"no new load" contract isn't honored for HTTP/2.I have a fix + test ready (shut down the connector's contained
Gracefulbeans, keepingshutdown()completion gated on acceptors/endpoints as before). Opened #15472 — happy to adjust the approach or hand it off if you'd prefer to take it a different way.Related: #15368/#15435 (client side of the same graceful-shutdown behavior), #13602 (a separate shutdown()-then-stop() hang in the same area).
lorban commentedon Aug 21, 2026
This seems similar to #13602: you should not call
Connector.shutdown()butConnector.stop()instead.Here following sample seems to do what you're looking for:
Did I miss anything?
serhiy-bzhezytskyy commentedon Aug 31, 2026
@lorban — you're right that
stop()does what both reporters were reaching for, and I'm not arguing that these two PRs should land as they are. I'd rather ask whether they should stay open at all.What I can add is a measurement on current
jetty-12.1.x, with only the tests applied and the production change reverted:connector.shutdown()still sends no GOAWAY: the client never receives one, so a live HTTP/2 session keeps accepting new streams until the shutdown idle timeout.shutdown()still never completes afterstop(); the test times out.So both still reproduce. If
shutdown()is meant to honour theGracefulcontract for HTTP/2, the defects are still there. If it isn't — ifstop()is simply the API andshutdown()was never intended to reach the session — then these are working-as-intended and I'll close #15472 and #15473.Two things on my own side, for accuracy. Of the three tests,
testConnectorShutdownThenStopCompletesFutureOnHTTP2now passes without the production change, so it no longer proves anything and would come out either way. And neither PR overlaps #15628: both touchjetty-server'sAbstractConnector, not the HTTP/2 client transport.Either answer works for me — I'd just rather not leave two PRs open if the premise is wrong.
lorban commentedon Aug 31, 2026
@serhiy-bzhezytskyy
Graceful.shutdown()is not exactly meant to be called directly: all implementations are meant to perform the necessary cleanup for the component upon which the call is performed, and it's up to the caller to arrange for callingshutdown()on every necessary component in the right order. In a nutshell, this is an implementation detail of someLifeCycle.stop()implementations.So if calling
Server.stop()orConnector.stop()does send GOAWAY and waits the appropriate time, then everything works as intended.That doesn't mean we can't improve a thing or two in that area, including in the field of docs.
serhiy-bzhezytskyy commentedon Aug 31, 2026
Thanks, I see. #15472/#15473 closed.
lorban commentedon Sep 11, 2026
Graceful.shutdown() is not meant to be called directly, closing as misuse.