This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new 6d046a2209 Stop removed realms when combined realm stops
6d046a2209 is described below
commit 6d046a22092854527ab14c74d29ccd36c5009e68
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Sep 16 08:23:46 2026 +0100
Stop removed realms when combined realm stops
---
java/org/apache/catalina/realm/CombinedRealm.java | 20 ++++++++++++--------
.../org/apache/catalina/realm/TestCombinedRealm.java | 4 ++--
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/java/org/apache/catalina/realm/CombinedRealm.java
b/java/org/apache/catalina/realm/CombinedRealm.java
index 19c1516fce..755171fcbe 100644
--- a/java/org/apache/catalina/realm/CombinedRealm.java
+++ b/java/org/apache/catalina/realm/CombinedRealm.java
@@ -318,7 +318,17 @@ public class CombinedRealm extends RealmBase {
// Stop this realm, then the sub-realms (reverse order to start)
super.stopInternal();
for (Realm realm : realms) {
- if (realm instanceof Lifecycle) {
+ stopRealm(realm);
+ }
+ for (Realm realm : realmsToDestroy) {
+ stopRealm(realm);
+ }
+ }
+
+
+ private void stopRealm(Realm realm) {
+ if (realm instanceof Lifecycle) {
+ if (((Lifecycle) realm).getState().isAvailable()) {
try {
((Lifecycle) realm).stop();
} catch (LifecycleException e) {
@@ -346,14 +356,8 @@ public class CombinedRealm extends RealmBase {
private void destroyRealm(Realm realm) {
+ stopRealm(realm);
if (realm instanceof Lifecycle) {
- if (((Lifecycle) realm).getState().isAvailable()) {
- try {
- ((Lifecycle) realm).stop();
- } catch (LifecycleException e) {
- log.error(sm.getString("combinedRealm.realmStopFail",
realm.getClass().getName()), e);
- }
- }
try {
((Lifecycle) realm).destroy();
} catch (LifecycleException e) {
diff --git a/test/org/apache/catalina/realm/TestCombinedRealm.java
b/test/org/apache/catalina/realm/TestCombinedRealm.java
index de3803bfd0..30b1b074ac 100644
--- a/test/org/apache/catalina/realm/TestCombinedRealm.java
+++ b/test/org/apache/catalina/realm/TestCombinedRealm.java
@@ -235,10 +235,10 @@ public class TestCombinedRealm {
Assert.assertEquals(0, removed.getStopCount());
Assert.assertEquals(0, removed.getDestroyCount());
- // Stopping the combined Realm only stops the Realms it still contains
+ // Stopping the combined Realm stops the Realms it still contains and
those that were removed
combinedRealm.stop();
Assert.assertEquals(LifecycleState.STOPPED, retained.getState());
- Assert.assertEquals(LifecycleState.STARTED, removed.getState());
+ Assert.assertEquals(LifecycleState.STOPPED, removed.getState());
// Destroying the combined Realm must clean up both, each exactly once
combinedRealm.destroy();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]