Yavor16 opened a new issue, #2640:
URL: https://github.com/apache/logging-log4j2/issues/2640

   ## Description
   
   We are using file logging because we have many steps and after every step 
the logs are persisted in the database and the files are deleted. While our 
application was running on Java 11, we had no problems. When we switched to 
Java 17, the problems started. I used the GC logs, jcmd and jmap to find out 
that module/org.apache.logging.log4j.core.util.WatchManager is not garbage 
collected. Instead of unloading the WatchManager class, the logs are full with:
   
   Dynamic nestmate: unnamed 
module/org.apache.logging.log4j.core.util.WatchManager$$Lambda$6426/0x00000007f2680228,
 nest_host org.apache.logging.log4j.core.util.WatchManager, is hidden
   LookupDefineClass: 
org/apache/logging/log4j/core/util/WatchManager$$Lambda$6427 - with dynamic 
nest-host org.apache.logging.log4j.core.util.WatchManager, hidden, strong, 
without vm annotation
   
   We tried switching the GC-s but nothing worked. We tried different log4j 
versions. Now we use 2.23.1.
   
   We've tried to stop/close everything.
   
   `
   FileUtils.deleteQuietly(log)
   loggerContext.stop();
             
loggerContext.getConfiguration().getAppenders().values().forEach(appender -> {
                 loggerContext.getRootLogger().removeAppender(appender);
                 appender.stop();
             });
             
loggerContext.getConfiguration().getWatchManager().getConfigurationWatchers().keySet().forEach(key
 -> {
                 
loggerContext.getConfiguration().getWatchManager().unwatch(key);
             });
             loggerContext.getConfiguration().getWatchManager().reset();
             
loggerContext.getConfiguration().getLoggers().values().forEach(AbstractLifeCycle::stop);
             
loggerContext.getConfiguration().getLoggers().values().forEach(loggerConfig -> {
                 loggerConfig.getAppenderRefs().clear();
             });
             loggerContext.getConfiguration().getWatchManager().stop();
             
loggerContext.getConfiguration().getWatchManager().getConfigurationWatchers().clear();
             LogManager.shutdown();
   `
   
   We create new FileAppender, LoggerContext, LoggerConfig for every new log.
   `
   LoggerContext loggerContext = new LoggerContext(loggerName);
   FileAppender fileAppender = FileAppender.newBuilder()
                              .setName(loggerName)
                              .withFileName(logFile.toString())
                              .setLayout(layoutCreatorFunction.apply(context))
                              .setConfiguration(context.getConfiguration())
                              .build();
   fileAppender.start();
   loggerContext.getConfiguration()
                        .addAppender(fileAppender);
    LoggerConfig loggerConfig = loggerContext.getConfiguration()
                               .getLoggerConfig(loggerName);
   Other config stuff
   loggerContext.updateLoggers();
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to