Log4j 2
  1. Log4j 2
  2. LOG4J2-619

Unable to recover after loading corrupted XML

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-rc1
    • Fix Version/s: 2.0-rc2
    • Component/s: None
    • Labels:
      None
    • Environment:

      CentOS 6.5, Oracle Java 7 u55

      Description

      Steps to reproduce:
      1) auto-reloading of log4j 2.x configuration from XML is enabled
      2) system is started and producing logs
      3) change XML configuration, so it's not valid XML any longer
      4) Wait till it would be picked up -> no more logging info is produced, exception can be found from logs (see below).
      5) Fix XML configuration -> it's not getting reloaded anymore, only java restart can fix the problem.

      log4j2.xml org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 7; The processi
      ng instruction target matching "[xX][mM][lL]" is not allowed.
      at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
      at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:347)
      at org.apache.logging.log4j.core.config.XMLConfiguration.<init>(XMLConfiguration.java:145)
      at org.apache.logging.log4j.core.config.XMLConfiguration.reconfigure(XMLConfiguration.java:286)
      at org.apache.logging.log4j.core.LoggerContext.onChange(LoggerContext.java:421)
      at org.apache.logging.log4j.core.config.FileConfigurationMonitor.checkConfiguration(FileConfigurationMonitor.java:79)
      at org.apache.logging.log4j.core.Logger$PrivateConfig.filter(Logger.java:279)
      at org.apache.logging.log4j.core.Logger.isEnabled(Logger.java:117)
      at org.apache.logging.log4j.spi.AbstractLoggerWrapper.isEnabled(AbstractLoggerWrapper.java:82)
      at org.apache.logging.log4j.spi.AbstractLogger.isDebugEnabled(AbstractLogger.java:1071)
      at org.slf4j.impl.SLF4JLogger.isDebugEnabled(SLF4JLogger.java:174)
      at org.apache.commons.logging.impl.SLF4JLocationAwareLog.isDebugEnabled(SLF4JLocationAwareLog.java:67)
      ....

      ERROR No logging configuration

        Issue Links

          Activity

          Hide
          Ralph Goers added a comment -

          I think this issue may have been fixed with the changes made in LOG4J-620. Can you please retest with the latest in trunk?

          Show
          Ralph Goers added a comment - I think this issue may have been fixed with the changes made in LOG4J-620. Can you please retest with the latest in trunk?
          Hide
          Scott Harrington added a comment -

          Hi, I am not the original submitter but I observed this as well, in both rc1 and in trunk r1602630, and it turns out to be easy to fix (patch is attached).

          The issue is that XmlConfiguration constructor (a) swallows exceptions, and (b) encounters the parse failure before populating the FileConfigurationMonitor. So reconfigure() returns an instance that is useless AND that will never check the file again.

          A similar issue might exist in JsonConfiguration but I don't have an easy way to test that.

          An alternate fix would be to NOT swallow exceptions in the constructor. But I looked at the other callers e.g. XmlConfigurationFactory and concluded those cases are probably o.k. with a useless Configuration (unlike reconfigure which really shouldn't rip the monitor out from under us).

          Show
          Scott Harrington added a comment - Hi, I am not the original submitter but I observed this as well, in both rc1 and in trunk r1602630, and it turns out to be easy to fix (patch is attached). The issue is that XmlConfiguration constructor (a) swallows exceptions, and (b) encounters the parse failure before populating the FileConfigurationMonitor. So reconfigure() returns an instance that is useless AND that will never check the file again. A similar issue might exist in JsonConfiguration but I don't have an easy way to test that. An alternate fix would be to NOT swallow exceptions in the constructor. But I looked at the other callers e.g. XmlConfigurationFactory and concluded those cases are probably o.k. with a useless Configuration (unlike reconfigure which really shouldn't rip the monitor out from under us).
          Hide
          Matt Sicker added a comment -

          I've applied the patch in r1602778. Could you verify if this fixes the error?

          Show
          Matt Sicker added a comment - I've applied the patch in r1602778. Could you verify if this fixes the error?
          Hide
          Scott Harrington added a comment -

          Hi Matt, I've updated to 1602778 and the XML reconfigure cycle works as expected when invalid XML is encountered. Thanks!

          Show
          Scott Harrington added a comment - Hi Matt, I've updated to 1602778 and the XML reconfigure cycle works as expected when invalid XML is encountered. Thanks!
          Hide
          Matt Sicker added a comment -

          Fixed in r1602778 and verified by user.

          Show
          Matt Sicker added a comment - Fixed in r1602778 and verified by user.
          Hide
          Ralph Goers added a comment -

          The fix was bad. It checked for a rootElement being null and if it was it returned null. But it never returned the new configuration, so the reconfigure method was always returning null and the new configuration never took effect. Fixed in revision 1603048.

          Show
          Ralph Goers added a comment - The fix was bad. It checked for a rootElement being null and if it was it returned null. But it never returned the new configuration, so the reconfigure method was always returning null and the new configuration never took effect. Fixed in revision 1603048.

            People

            • Assignee:
              Unassigned
              Reporter:
              Sergey Burkov
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development