Skip to content

Commit 2581c5c

Browse files
committed
Upgrade to Tomcat 10.1.19
Closes gh-39663
1 parent 1c5858e commit 2581c5c

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ kotlinVersion=1.8.22
1313
mavenVersion=3.9.4
1414
nativeBuildToolsVersion=0.9.28
1515
springFrameworkVersion=6.0.17
16-
tomcatVersion=10.1.18
16+
tomcatVersion=10.1.19
1717

1818
kotlin.stdlib.default.dependency=false

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

Lines changed: 32 additions & 18 deletions
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-2024 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.
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.Collections;
2121
import java.util.List;
22+
import java.util.concurrent.CountDownLatch;
2223

2324
import org.apache.catalina.Container;
2425
import org.apache.catalina.Service;
@@ -51,32 +52,45 @@ final class GracefulShutdown {
5152

5253
void shutDownGracefully(GracefulShutdownCallback callback) {
5354
logger.info("Commencing graceful shutdown. Waiting for active requests to complete");
54-
new Thread(() -> doShutdown(callback), "tomcat-shutdown").start();
55+
CountDownLatch shutdownUnderway = new CountDownLatch(1);
56+
new Thread(() -> doShutdown(callback, shutdownUnderway), "tomcat-shutdown").start();
57+
try {
58+
shutdownUnderway.await();
59+
}
60+
catch (InterruptedException ex) {
61+
Thread.currentThread().interrupt();
62+
}
5563
}
5664

57-
private void doShutdown(GracefulShutdownCallback callback) {
58-
List<Connector> connectors = getConnectors();
59-
connectors.forEach(this::close);
65+
private void doShutdown(GracefulShutdownCallback callback, CountDownLatch shutdownUnderway) {
6066
try {
61-
for (Container host : this.tomcat.getEngine().findChildren()) {
62-
for (Container context : host.findChildren()) {
63-
while (isActive(context)) {
64-
if (this.aborted) {
65-
logger.info("Graceful shutdown aborted with one or more requests still active");
66-
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
67-
return;
67+
List<Connector> connectors = getConnectors();
68+
connectors.forEach(this::close);
69+
shutdownUnderway.countDown();
70+
try {
71+
for (Container host : this.tomcat.getEngine().findChildren()) {
72+
for (Container context : host.findChildren()) {
73+
while (isActive(context)) {
74+
if (this.aborted) {
75+
logger.info("Graceful shutdown aborted with one or more requests still active");
76+
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
77+
return;
78+
}
79+
Thread.sleep(50);
6880
}
69-
Thread.sleep(50);
7081
}
7182
}
72-
}
7383

84+
}
85+
catch (InterruptedException ex) {
86+
Thread.currentThread().interrupt();
87+
}
88+
logger.info("Graceful shutdown complete");
89+
callback.shutdownComplete(GracefulShutdownResult.IDLE);
7490
}
75-
catch (InterruptedException ex) {
76-
Thread.currentThread().interrupt();
91+
finally {
92+
shutdownUnderway.countDown();
7793
}
78-
logger.info("Graceful shutdown complete");
79-
callback.shutdownComplete(GracefulShutdownResult.IDLE);
8094
}
8195

8296
private List<Connector> getConnectors() {

0 commit comments

Comments
 (0)