Skip to content

Commit

Permalink
Upgrade to Tomcat 10.1.19
Browse files Browse the repository at this point in the history
Closes gh-39673
  • Loading branch information
wilkinsona committed Feb 21, 2024
1 parent d86fa72 commit 71e3a92
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ kotlinVersion=1.9.22
mavenVersion=3.9.4
nativeBuildToolsVersion=0.9.28
springFrameworkVersion=6.1.4
tomcatVersion=10.1.18
tomcatVersion=10.1.19

kotlin.stdlib.default.dependency=false
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import org.apache.catalina.Container;
import org.apache.catalina.Service;
Expand Down Expand Up @@ -51,32 +52,44 @@ final class GracefulShutdown {

void shutDownGracefully(GracefulShutdownCallback callback) {
logger.info("Commencing graceful shutdown. Waiting for active requests to complete");
new Thread(() -> doShutdown(callback), "tomcat-shutdown").start();
CountDownLatch shutdownUnderway = new CountDownLatch(1);
new Thread(() -> doShutdown(callback, shutdownUnderway), "tomcat-shutdown").start();
try {
shutdownUnderway.await();
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}

private void doShutdown(GracefulShutdownCallback callback) {
List<Connector> connectors = getConnectors();
connectors.forEach(this::close);
private void doShutdown(GracefulShutdownCallback callback, CountDownLatch shutdownUnderway) {
try {
for (Container host : this.tomcat.getEngine().findChildren()) {
for (Container context : host.findChildren()) {
while (!this.aborted && isActive(context)) {
Thread.sleep(50);
}
if (this.aborted) {
logger.info("Graceful shutdown aborted with one or more requests still active");
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
return;
List<Connector> connectors = getConnectors();
connectors.forEach(this::close);
shutdownUnderway.countDown();
try {
for (Container host : this.tomcat.getEngine().findChildren()) {
for (Container context : host.findChildren()) {
while (!this.aborted && isActive(context)) {
Thread.sleep(50);
}
if (this.aborted) {
logger.info("Graceful shutdown aborted with one or more requests still active");
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
return;
}
}
}
}

catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
logger.info("Graceful shutdown complete");
callback.shutdownComplete(GracefulShutdownResult.IDLE);
}
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
finally {
shutdownUnderway.countDown();
}
logger.info("Graceful shutdown complete");
callback.shutdownComplete(GracefulShutdownResult.IDLE);
}

private List<Connector> getConnectors() {
Expand Down

0 comments on commit 71e3a92

Please sign in to comment.