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

Composite configuration unable to recover after loading corrupted XML

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.12.0
    • None
    • Core
    • None

    Description

      How to reproduce:
      1) Use composite configuration consisting of XML configurations with monitorInterval set to reload changes in runtime
      2) Start the app and check that logs are written
      3) Change one of XML configurations (i.e. one with root logger configuration) to not valid XML
      4) After changes will be loaded events will be redirected to console
      5) Further changes of broken configuration file aren't watched anymore, only JVM restart could help

      Reason of that is how CompositeConfiguration handles reconfiguration: for each underlying configuration it will try to get new config via ConfigurationFactory. XML factory (didn't check the others) will return new configuration, and if source is broken it will be the default one. ConfiguratonFileWatcher for XML config will be registered only if config is valid and has monitorInterval property, so no further changes to this file will not be loaded until JVM restart.

      @Override
      public Configuration reconfigure() {
          LOGGER.debug("Reconfiguring composite configuration");
          final List<AbstractConfiguration> configs = new ArrayList<>();
          final ConfigurationFactory factory = ConfigurationFactory.getInstance();
          for (final AbstractConfiguration config : configurations) {
              final ConfigurationSource source = config.getConfigurationSource();
              final URI sourceURI = source.getURI();
              Configuration currentConfig = config;
              if (sourceURI == null) {
                  LOGGER.warn("Unable to determine URI for configuration {}, changes to it will be ignored",
                          config.getName());
              } else {
                  currentConfig = factory.getConfiguration(getLoggerContext(), config.getName(), sourceURI);
                  if (currentConfig == null) {
                      LOGGER.warn("Unable to reload configuration {}, changes to it will be ignored", config.getName());
                  }
              }
              configs.add((AbstractConfiguration) currentConfig);
          }
          return new CompositeConfiguration(configs);
      }
      

      This might be fixed with two changes:
      1) CompositeConfiguration should use reconfigure() on underlying configurations if possible
      2) If any of the reconfigure() calls returns null, then null should be returned so all changes will be ignored

      Attachments

        Activity

          People

            Unassigned Unassigned
            dmmi Dmitrii Miliukov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: