Skip to content

Commit 64e76ba

Browse files
committed
Merge branch '2.3.x' into 2.4.x
Closes gh-26607
2 parents 6874c42 + b6e860b commit 64e76ba

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyReactiveWebServerFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -169,6 +169,7 @@ protected Server createJettyServer(JettyHttpHandlerAdapter servlet) {
169169
InetSocketAddress address = new InetSocketAddress(getAddress(), port);
170170
Server server = new Server(getThreadPool());
171171
server.addConnector(createConnector(address, server));
172+
server.setStopTimeout(0);
172173
ServletHolder servletHolder = new ServletHolder(servlet);
173174
servletHolder.setAsyncSupported(true);
174175
ServletContextHandler contextHandler = new ServletContextHandler(server, "/", false, false);

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyServletWebServerFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -169,6 +169,7 @@ public WebServer getWebServer(ServletContextInitializer... initializers) {
169169
private Server createServer(InetSocketAddress address) {
170170
Server server = new Server(getThreadPool());
171171
server.setConnectors(new Connector[] { createConnector(address, server) });
172+
server.setStopTimeout(0);
172173
return server;
173174
}
174175

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/reactive/server/AbstractReactiveWebServerFactoryTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,30 @@ void givenAnInflightRequestWhenTheServerIsStoppedThenGracefulShutdownCallbackIsC
424424
blockingHandler.completeOne();
425425
}
426426

427+
@Test
428+
void whenARequestIsActiveAfterGracefulShutdownEndsThenStopWillComplete() throws InterruptedException {
429+
AbstractReactiveWebServerFactory factory = getFactory();
430+
factory.setShutdown(Shutdown.GRACEFUL);
431+
BlockingHandler blockingHandler = new BlockingHandler();
432+
this.webServer = factory.getWebServer(blockingHandler);
433+
this.webServer.start();
434+
Mono<ResponseEntity<Void>> request = getWebClient(this.webServer.getPort()).build().get().retrieve()
435+
.toBodilessEntity();
436+
AtomicReference<ResponseEntity<Void>> responseReference = new AtomicReference<>();
437+
CountDownLatch responseLatch = new CountDownLatch(1);
438+
request.subscribe((response) -> {
439+
responseReference.set(response);
440+
responseLatch.countDown();
441+
});
442+
blockingHandler.awaitQueue();
443+
AtomicReference<GracefulShutdownResult> result = new AtomicReference<>();
444+
this.webServer.shutDownGracefully(result::set);
445+
this.webServer.stop();
446+
Awaitility.await().atMost(Duration.ofSeconds(30))
447+
.until(() -> GracefulShutdownResult.REQUESTS_ACTIVE == result.get());
448+
blockingHandler.completeOne();
449+
}
450+
427451
@Test
428452
void whenARequestIsActiveThenStopWillComplete() throws InterruptedException, BrokenBarrierException {
429453
AbstractReactiveWebServerFactory factory = getFactory();

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,31 @@ void whenARequestIsActiveThenStopWillComplete() throws InterruptedException, Bro
11211121
}
11221122
}
11231123

1124+
@Test
1125+
void whenARequestIsActiveAfterGracefulShutdownEndsThenStopWillComplete()
1126+
throws InterruptedException, BrokenBarrierException {
1127+
AbstractServletWebServerFactory factory = getFactory();
1128+
factory.setShutdown(Shutdown.GRACEFUL);
1129+
BlockingServlet blockingServlet = new BlockingServlet();
1130+
this.webServer = factory
1131+
.getWebServer((context) -> context.addServlet("blockingServlet", blockingServlet).addMapping("/"));
1132+
this.webServer.start();
1133+
int port = this.webServer.getPort();
1134+
initiateGetRequest(port, "/");
1135+
blockingServlet.awaitQueue();
1136+
AtomicReference<GracefulShutdownResult> result = new AtomicReference<>();
1137+
this.webServer.shutDownGracefully(result::set);
1138+
this.webServer.stop();
1139+
Awaitility.await().atMost(Duration.ofSeconds(30))
1140+
.until(() -> GracefulShutdownResult.REQUESTS_ACTIVE == result.get());
1141+
try {
1142+
blockingServlet.admitOne();
1143+
}
1144+
catch (RuntimeException ex) {
1145+
1146+
}
1147+
}
1148+
11241149
protected Future<Object> initiateGetRequest(int port, String path) {
11251150
return initiateGetRequest(HttpClients.createMinimal(), port, path);
11261151
}

0 commit comments

Comments
 (0)