Repository navigation
Description
Jetty version(s)
12.1.1
Java version/vendor
JDK 21
Description
The future returned by calling Connector#shutdown() will never complete if Connector#close() is later called whilst there are HTTP/2 clients connected.
Use Case
I need the application to support a graceful shutdown using Connector#shutdown(), however if this is taking too long then the application can be interrupted for a faster shutdown, calling Connector#close().
How to reproduce?
public static void main(String[] args) throws Exception {
Server server = new Server();
ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(), new HTTP2CServerConnectionFactory());
connector.setPort(0);
connector.setShutdownIdleTimeout(15_000);
server.setConnectors(new Connector[] {connector});
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();
ContentResponse response = http2Client.newRequest(url)
.method(HttpMethod.GET)
.send();
log.info("Response {}", response);
// This future will wait for all connections to close
CompletableFuture<Void> shutdownFuture = server.getConnectors()[0].shutdown();
Thread.sleep(Duration.ofSeconds(1));
// This should forcibly close connections
server.getConnectors()[0].stop();
log.info("Waiting for shutdown future...");
shutdownFuture.get();
log.info("Shutdown completed");
System.exit(0);
}Output:
13:43:26.771 [main] INFO org.eclipse.jetty.server.Server - jetty-12.1.1; built: 2025-09-08T04:29:45.457Z; git: b7068950f9afa5f1df80e46053eda1d982895b03; jvm 21.0.7+6-LTS
13:43:26.805 [main] INFO o.e.jetty.server.AbstractConnector - Started oejs.ServerConnector@63475ace{HTTP/1.1, (http/1.1, h2c)}{0.0.0.0:34647}
13:43:26.812 [main] INFO org.eclipse.jetty.server.Server - Started oejs.Server@71e9ddb4{STARTING}[12.1.1,sto=0] @598ms
13:43:27.140 [main] INFO org.example.ShutdownStuck - Response HttpContentResponse[HTTP/2.0 404 null - 413 bytes]
13:43:28.145 [main] INFO o.e.jetty.server.AbstractConnector - Stopped oejs.ServerConnector@63475ace{HTTP/1.1, (http/1.1, h2c)}{0.0.0.0:0}
13:43:28.145 [main] INFO org.example.ShutdownStuck - Waiting for shutdown future...
(Note if the client is swapped to HTTP/1.1 then the future returns as expected)
Suspected cause
The _shutdown variable is set to null before the HTTP/2 endpoints finish disconnecting:
jetty.project/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java
Line 380 in b706895
| _shutdown = null; |
Contrast this with HTTP/1.1, when onEndPointClosed() the _shutdown variable is still present
I'm not sure however why the timing of HTTP/1.1 and HTTP/2 endpoint disconnection differs though?
Activity
serhiy-bzhezytskyy commentedon Jul 23, 2026
Root cause:
doStop()clears_shutdownbefore the asynchronous HTTP/2 endpoint disconnect firesonEndPointClosed(), so the finalShutdown.check()is skipped and theshutdown()future never completes. HTTP/1.1 disconnects synchronously enough to avoid the window, which matches your observation that swapping to HTTP/1.1 returns the future as expected — thanks for the precise repro and the pointer to the_shutdownline, that's exactly it.Opened #15473 with a fix:
isShutdownDone()treats a no-longer-running connector as done, anddoStop()completes the pending shutdown before clearing_shutdown. Test coversshutdown()-then-stop()including with a still-active stream.Related: #13569 / #15368 (same graceful-shutdown area).
lorban commentedon Aug 21, 2026
@jacob-pro There might be a bug lurking around (I haven't looked at the
shutdown()code yet) but it looks like the problem here is that you're mis-using the API.The following adaptation of your reproducer seems to work fine:
Could you please give it a try and let us know if the above does what you expect?
lorban commentedon Sep 11, 2026
Graceful.shutdown() is not meant to be called directly, see: #15473 (comment)