carterkozak commented on a change in pull request #273: LOG4J2-2606: 
Substantially improve async logging performance under heavy load
URL: https://github.com/apache/logging-log4j2/pull/273#discussion_r286754419
 
 

 ##########
 File path: 
log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLoggerDisruptor.java
 ##########
 @@ -202,32 +209,95 @@ private boolean hasLog4jBeenShutDown(final 
Disruptor<RingBufferLogEvent> aDisrup
         return false;
     }
 
-    public boolean tryPublish(final RingBufferLogEventTranslator translator) {
+    boolean tryPublish(final RingBufferLogEventTranslator translator) {
         try {
+            // Note: we deliberately access the volatile disruptor field 
afresh here.
+            // Avoiding this and using an older reference could result in 
adding a log event to the disruptor after it
+            // was shut down, which could cause the publishEvent method to 
hang and never return.
             return disruptor.getRingBuffer().tryPublishEvent(translator);
         } catch (final NullPointerException npe) {
             // LOG4J2-639: catch NPE if disruptor field was set to null in 
stop()
-            LOGGER.warn("[{}] Ignoring log event after log4j was shut down: {} 
[{}] {}", contextName,
-                    translator.level, translator.loggerName, 
translator.message.getFormattedMessage()
-                            + (translator.thrown == null ? "" : 
Throwables.toStringList(translator.thrown)));
+            logWarningOnNpeFromDisruptorPublish(translator);
 
 Review comment:
   Should allow the fast path to inline more readily as well :-)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to