You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2015/06/10 18:13:24 UTC

logging-log4j2 git commit: LOG4J2-1049 AsyncAppender now resets the thread interrupted flag after catching InterruptedException.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 4c95866dc -> ba3070e71


LOG4J2-1049 AsyncAppender now resets the thread interrupted flag after
catching InterruptedException.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/ba3070e7
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/ba3070e7
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/ba3070e7

Branch: refs/heads/master
Commit: ba3070e714172fe587e0bd5e9f8e0b72890a719a
Parents: 4c95866
Author: rpopma <rp...@apache.org>
Authored: Thu Jun 11 01:13:37 2015 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Jun 11 01:13:37 2015 +0900

----------------------------------------------------------------------
 .../log4j/core/appender/AsyncAppender.java      | 23 +++++++++++++++++---
 src/changes/changes.xml                         |  3 +++
 2 files changed, 23 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ba3070e7/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
index d2d3bfd..fc860e2 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AsyncAppender.java
@@ -150,13 +150,30 @@ public final class AsyncAppender extends AbstractAppender {
                 coreEvent.setEndOfBatch(false); // queue is definitely not empty!
                 appendSuccessful = thread.callAppenders(coreEvent);
             } else {
+                final Serializable serialized = Log4jLogEvent.serialize(coreEvent, includeLocation);
                 try {
                     // wait for free slots in the queue
-                    queue.put(Log4jLogEvent.serialize(coreEvent, includeLocation));
+                    queue.put(serialized);
                     appendSuccessful = true;
                 } catch (final InterruptedException e) {
-                    LOGGER.warn("Interrupted while waiting for a free slot in the AsyncAppender LogEvent-queue {}",
-                            getName());
+                    // LOG4J2-1049: Some applications use Thread.interrupt() to send
+                    // messages between application threads. This does not necessarily
+                    // mean that the queue is full. To prevent dropping a log message,
+                    // quickly try to offer the event to the queue again.
+                    // (Yes, this means there is a possibility the same event is logged twice.)
+                    //
+                    // Finally, catching the InterruptedException means the
+                    // interrupted flag has been cleared on the current thread.
+                    // This may interfere with the application's expectation of
+                    // being interrupted, so when we are done, we set the interrupted
+                    // flag again.
+                    appendSuccessful = queue.offer(serialized);
+                    if (!appendSuccessful) {
+                        LOGGER.warn("Interrupted while waiting for a free slot in the AsyncAppender LogEvent-queue {}",
+                        getName());
+                    }
+                    // set the interrupted flag again.
+                    Thread.currentThread().interrupt();
                 }
             }
         } else {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/ba3070e7/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index e22441f..d383b1f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,9 @@
   </properties>
   <body>
     <release version="2.4" date="2015-MM-DD" description="GA Release 2.4">
+      <action issue="LOG4J2-1049" dev="rpopma" type="fix" due-to="Robert Schaft">
+        AsyncAppender now resets the thread interrupted flag after catching InterruptedException.
+      </action>
       <action issue="LOG4J2-1048" dev="rpopma" type="fix" due-to="Nikhil">
         FileConfigurationMonitor unnecessarily calls System.currentTimeMillis causing high CPU usage.
       </action>