Skip to content

Commit f2ddf1c

Browse files
committed
Merge branch '3.1.x' into 3.2.x
While the bug fixed in 3.1.x (gh-39942) has already been addressed as a side-effect of the changes made in dbb2428, the change is merged forwards here to improve the consistency of the code between branches.
2 parents d2e9d66 + 81dc0cc commit f2ddf1c

File tree

1 file changed

+23
-17
lines changed
  • spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat

1 file changed

+23
-17
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/tomcat/GracefulShutdown.java

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,25 +67,15 @@ private void doShutdown(GracefulShutdownCallback callback, CountDownLatch shutdo
6767
List<Connector> connectors = getConnectors();
6868
connectors.forEach(this::close);
6969
shutdownUnderway.countDown();
70-
try {
71-
for (Container host : this.tomcat.getEngine().findChildren()) {
72-
for (Container context : host.findChildren()) {
73-
while (!this.aborted && isActive(context)) {
74-
Thread.sleep(50);
75-
}
76-
if (this.aborted) {
77-
logger.info("Graceful shutdown aborted with one or more requests still active");
78-
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
79-
return;
80-
}
81-
}
82-
}
70+
awaitInactiveOrAborted();
71+
if (this.aborted) {
72+
logger.info("Graceful shutdown aborted with one or more requests still active");
73+
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
8374
}
84-
catch (InterruptedException ex) {
85-
Thread.currentThread().interrupt();
75+
else {
76+
logger.info("Graceful shutdown complete");
77+
callback.shutdownComplete(GracefulShutdownResult.IDLE);
8678
}
87-
logger.info("Graceful shutdown complete");
88-
callback.shutdownComplete(GracefulShutdownResult.IDLE);
8979
}
9080
finally {
9181
shutdownUnderway.countDown();
@@ -105,6 +95,22 @@ private void close(Connector connector) {
10595
connector.getProtocolHandler().closeServerSocketGraceful();
10696
}
10797

98+
private void awaitInactiveOrAborted() {
99+
try {
100+
for (Container host : this.tomcat.getEngine().findChildren()) {
101+
for (Container context : host.findChildren()) {
102+
while (!this.aborted && isActive(context)) {
103+
Thread.sleep(50);
104+
}
105+
}
106+
}
107+
108+
}
109+
catch (InterruptedException ex) {
110+
Thread.currentThread().interrupt();
111+
}
112+
}
113+
108114
private boolean isActive(Container context) {
109115
try {
110116
if (((StandardContext) context).getInProgressAsyncCount() > 0) {

0 commit comments

Comments
 (0)