You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Martin Pelak (Jira)" <ji...@apache.org> on 2021/10/16 09:29:00 UTC

[jira] [Created] (LOG4J2-3173) KafkaAppender for log4j2 prevents an app from terminating

Martin Pelak created LOG4J2-3173:
------------------------------------

             Summary: KafkaAppender for log4j2 prevents an app from terminating
                 Key: LOG4J2-3173
                 URL: https://issues.apache.org/jira/browse/LOG4J2-3173
             Project: Log4j 2
          Issue Type: Bug
          Components: Appenders
            Reporter: Martin Pelak
         Attachments: HelloWorldLog4j.zip, kafka-appender-it-hangs-here.png, log4j2.xml

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.
{code:java}
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();
    }
}
{code}
The one minutes delay (per message) is configured by [max.block.ms|http://kafka.apache.org/documentation.html#producerconfigs_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 

!kafka-appender-it-hangs-here.png!



--
This message was sent by Atlassian Jira
(v8.3.4#803005)