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

Root LoggerConfig is corrupted leading to stack overflow

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.6.2, 2.7
    • None
    • Core
    • None

    Description

      The simple repro code below demonstrates the corruption of the LoggerConfig instance for root logger. Executing the main leads to unstopped recursion, leading to stack overflow. The recursion includes three method calls, shown in this stack trace fragment:

      at org.apache.logging.log4j.core.config.LoggerConfig.logParent(LoggerConfig.java:381)
      at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:376)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:359)
      at org.apache.logging.log4j.core.config.LoggerConfig.logParent(LoggerConfig.java:381)
      at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:376)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:359)
      at org.apache.logging.log4j.core.config.LoggerConfig.logParent(LoggerConfig.java:381)
      at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:376)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:359)

      The basic problem is that 'logParent' becomes no-op (ends recursion) if additivity is off or if logger config's parent is null, otherwise recusrion continues.

      In the repro case, the root logger config points to itself as parent.

      I expect that when adding a logger to Configuration, the LoggerConfig should be specific to the named logger. So, the stack overflow could be avoided if Configuration.addLogger checked that the LoggerConfig's name matched the input logger name.

      Repro code:
      String loggerName = "new.logger.name";
      LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
      Configuration config = ctx.getConfiguration();
      LoggerConfig logCfg = config.getLoggerConfig(loggerName);
      config.addLogger(loggerName, logCfg);
      ctx.updateLoggers();
      LogManager.getLogger(loggerName).error("...by: "loggerName"....");

      Attachments

        1. ReproLoggerConfigBug.java
          1 kB
          Rod Burgett

        Activity

          People

            Unassigned Unassigned
            rod.burgett@computer.org Rod Burgett
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: