Skip to content

Commit 71e3a92

Browse files
committed
Upgrade to Tomcat 10.1.19
Closes gh-39673
1 parent d86fa72 commit 71e3a92

File tree

2 files changed

+33
-20
lines changed

2 files changed

+33
-20
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ kotlinVersion=1.9.22
1414
mavenVersion=3.9.4
1515
nativeBuildToolsVersion=0.9.28
1616
springFrameworkVersion=6.1.4
17-
tomcatVersion=10.1.18
17+
tomcatVersion=10.1.19
1818

1919
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 & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 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,44 @@ 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 (!this.aborted && isActive(context)) {
64-
Thread.sleep(50);
65-
}
66-
if (this.aborted) {
67-
logger.info("Graceful shutdown aborted with one or more requests still active");
68-
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
69-
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 (!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+
}
7081
}
7182
}
7283
}
73-
84+
catch (InterruptedException ex) {
85+
Thread.currentThread().interrupt();
86+
}
87+
logger.info("Graceful shutdown complete");
88+
callback.shutdownComplete(GracefulShutdownResult.IDLE);
7489
}
75-
catch (InterruptedException ex) {
76-
Thread.currentThread().interrupt();
90+
finally {
91+
shutdownUnderway.countDown();
7792
}
78-
logger.info("Graceful shutdown complete");
79-
callback.shutdownComplete(GracefulShutdownResult.IDLE);
8093
}
8194

8295
private List<Connector> getConnectors() {

0 commit comments

Comments
 (0)