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

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      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

            • Assignee:
              vy Volkan Yazici
              Reporter:
              wuqian wuqian
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: