This is an automated email from the ASF dual-hosted git repository.

ckozak pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git


The following commit(s) were added to refs/heads/master by this push:
     new e24e2e8  LOG4J2-3102: AsyncAppender background thread is a daemon
e24e2e8 is described below

commit e24e2e8901ccfff1b7e6c5b8d40b707bfc91c843
Author: Carter Kozak <[email protected]>
AuthorDate: Fri Jun 4 10:01:03 2021 -0400

    LOG4J2-3102: AsyncAppender background thread is a daemon
---
 .../log4j/core/appender/AsyncAppenderEventDispatcher.java        | 1 +
 .../apache/logging/log4j/core/appender/AsyncAppenderTest.java    | 9 +++++++++
 src/changes/changes.xml                                          | 4 ++++
 3 files changed, 14 insertions(+)

diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppenderEventDispatcher.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppenderEventDispatcher.java
index a01f68d..d9efc94 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppenderEventDispatcher.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppenderEventDispatcher.java
@@ -50,6 +50,7 @@ class AsyncAppenderEventDispatcher extends Log4jThread {
             final List<AppenderControl> appenders,
             final BlockingQueue<LogEvent> queue) {
         super("AsyncAppenderEventDispatcher-" + 
THREAD_COUNTER.incrementAndGet() + "-" + name);
+        this.setDaemon(true);
         this.errorAppender = errorAppender;
         this.appenders = appenders;
         this.queue = queue;
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
index fad0cb7..68abb56 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/AsyncAppenderTest.java
@@ -29,6 +29,7 @@ import org.junit.jupiter.api.Timeout;
 
 import java.util.List;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 import static org.junit.jupiter.api.Assertions.*;
 
@@ -74,6 +75,14 @@ class AsyncAppenderTest {
     void defaultAsyncAppenderConfig(final LoggerContext context) throws 
InterruptedException {
         rewriteTest(context);
         exceptionTest(context);
+
+        List<Thread> backgroundThreads = 
Thread.getAllStackTraces().keySet().stream()
+                .filter(AsyncAppenderEventDispatcher.class::isInstance)
+                .collect(Collectors.toList());
+        assertFalse(backgroundThreads.isEmpty(), "Failed to locate background 
thread");
+        for (Thread thread : backgroundThreads) {
+            assertTrue(thread.isDaemon(), "AsyncAppender should use daemon 
threads");
+        }
     }
 
     @Test
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 077fbd2..f7cc337 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -208,6 +208,10 @@
         Allow a PatternSelector to be specified on GelfLayout.
       </action>
       <!-- FIXES -->
+      <action issue="LOG4J2-3102" dev="ckozak" type="fix">
+        Fix a regression in 2.14.1 which allowed the AsyncAppender background 
thread to keep the JVM alive because
+        the daemon flag was not set.
+      </action>
       <action issue="LOG4J2-3103" dev="ckozak" type="fix" due-to="Mike Glazer">
         Fix race condition which can result in ConcurrentModificationException 
on context.stop.
       </action>

Reply via email to