This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 2a362e8a01 Handle case where listener receives destroy but not init
event
2a362e8a01 is described below
commit 2a362e8a014e7857dc9491e9fcb22b243e268b9c
Author: Mark Thomas <[email protected]>
AuthorDate: Fri Jun 14 18:34:10 2024 +0100
Handle case where listener receives destroy but not init event
---
java/org/apache/catalina/core/AprLifecycleListener.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/java/org/apache/catalina/core/AprLifecycleListener.java
b/java/org/apache/catalina/core/AprLifecycleListener.java
index f65c040d07..5ef6585fc9 100644
--- a/java/org/apache/catalina/core/AprLifecycleListener.java
+++ b/java/org/apache/catalina/core/AprLifecycleListener.java
@@ -103,6 +103,7 @@ public class AprLifecycleListener implements
LifecycleListener {
// Guarded by lock
private static int referenceCount = 0;
+ private boolean instanceInitialized = false;
public static boolean isAprAvailable() {
@@ -131,6 +132,7 @@ public class AprLifecycleListener implements
LifecycleListener {
if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType())) {
synchronized (lock) {
+ instanceInitialized = true;
if (!(event.getLifecycle() instanceof Server)) {
log.warn(sm.getString("listener.notServer",
event.getLifecycle().getClass().getSimpleName()));
}
@@ -163,8 +165,12 @@ public class AprLifecycleListener implements
LifecycleListener {
}
} else if (Lifecycle.AFTER_DESTROY_EVENT.equals(event.getType())) {
synchronized (lock) {
- if (--referenceCount != 0) {
- // Still being used (note test is performed after
reference count is decremented)
+ // Instance may get destroyed without ever being initialized
+ if (instanceInitialized) {
+ referenceCount --;
+ }
+ if (referenceCount != 0) {
+ // Still being used
return;
}
if (!AprStatus.isAprAvailable()) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]