Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-3173

KafkaAppender for log4j2 prevents an app from terminating

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • Appenders
    • None

    Description

      I have created a simple java `HelloWorld` app. When I start Kafka and then the app, all messages are logged to Kafka and my app finishes with exit code 0.

      However, if I start the app without starting Kafka, it seems that Kafka Appender prevents the app from terminating. It tries to send all logged messages. The termination time depends on  the number of logged messages. Each messages adds an extra one minute delay. So if one message has been logged, there is one minutes delay. It is two minutes for two messages and so on. 

      I found out that if I stop the Kafka appender manually, the app terminates without any delays.

      public class HelloWorld {
          private static final Logger logger = LogManager.getLogger(HelloWorld.class);
      
          public static void main(String[] args) throws InterruptedException {
              logger.info("test1");
              logger.error("test2");
      
              LoggerContext context = (LoggerContext) LogManager.getContext(false);
              KafkaAppender kafkaAppender = context.getConfiguration().getAppender("Kafka");
              kafkaAppender.stop();
      
              LogManager.shutdown();
          }
      }
      

      The one minutes delay (per message) is configured by max.block.ms. The parameter syncSend seems to have no affect.

      It is important for us that the app runs and terminates without any delays, even if some messages were lost.

      I tried to debug it and found out where it hangs, see 

      Attachments

        1. log4j2.xml
          1 kB
          Martin Pelak
        2. HelloWorldLog4j.zip
          7 kB
          Martin Pelak
        3. kafka-appender-it-hangs-here.png
          206 kB
          Martin Pelak

        Issue Links

          Activity

            People

              Unassigned Unassigned
              MPeli Martin Pelak
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: