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

If loggercontext got reconfigured and kafka appender got recreated, the previous producer can not be closed, which cause thread leak

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • None
    • None

    Description

      If loggercontext got reconfigured and kafka appender got recreated, the previous kafka producer thread can not be closed, which cause thread leak

       

      Repeat steps:

      xml configured to use kafka appender

      LoggerContext.getContext(false).reconfigure();
      LoggerContext.getContext(false).reconfigure();
      LoggerContext.getContext(false).reconfigure();
      LoggerContext.getContext(false).reconfigure();
      LoggerContext.getContext(false).reconfigure();
      LoggerContext.getContext(false).reconfigure();
      LoggerContext.getContext(false).reconfigure();
      LoggerContext.getContext(false).reconfigure();

       

      Resolution:

      In case the abstractlogmanager always cache the latest new producer and old producer can not be released.

      When creating new kafkamanager, add a logic to release previous kafka producer.

       

      public void startup() {
      // If loggercontext reconfigured and kafka appender got recreated, the previous producer can not be closed
      // which cause thread leak
      if(producer != null)

      { producer.close(); }

      producer = producerFactory.newKafkaProducer(config);
      }

       

      Attachments

        Activity

          People

            vy Volkan Yazici
            wuqian wuqian
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: