Occasionally, when shutting down ES instances using Ctrl-C, the following is logged a lot before exiting:

    The system environment variables are not available to Log4j due to security restrictions: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getenv.*")
    java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "getenv.*")
    	at java.base/java.security.AccessControlContext.checkPermission(AccessControlContext.java:485)
    	at java.base/java.security.AccessController.checkPermission(AccessController.java:1068)
    	at java.base/java.lang.SecurityManager.checkPermission(SecurityManager.java:411)
    	at java.base/java.lang.System.getenv(System.java:1196)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.EnvironmentPropertySource.containsProperty(EnvironmentPropertySource.java:99)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil$Environment.get(PropertiesUtil.java:513)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil$Environment.access$200(PropertiesUtil.java:434)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil.getStringProperty(PropertiesUtil.java:382)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil.getBooleanProperty(PropertiesUtil.java:169)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.status.StatusLogger.isDebugPropertyEnabled(StatusLogger.java:143)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.status.StatusLogger.logMessage(StatusLogger.java:295)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.log(AbstractLogger.java:2117)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2205)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2159)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2142)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2017)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1983)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:740)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.appender.DefaultErrorHandler.error(DefaultErrorHandler.java:61)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.appenderErrorHandlerMessage(AppenderControl.java:118)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.isRecursiveCall(AppenderControl.java:110)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.shouldSkip(AppenderControl.java:93)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:86)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:675)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:633)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:616)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:552)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.Logger.log(Logger.java:161)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2205)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2159)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2142)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2017)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1983)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.log(AbstractLogger.java:1652)
    	at org.elasticsearch.server@8.5.0-SNAPSHOT/org.elasticsearch.common.logging.LoggingOutputStream.log(LoggingOutputStream.java:108)
    	at org.elasticsearch.server@8.5.0-SNAPSHOT/org.elasticsearch.common.logging.LoggingOutputStream.flush(LoggingOutputStream.java:93)
    	at org.elasticsearch.server@8.5.0-SNAPSHOT/org.elasticsearch.common.logging.LoggingOutputStream.write(LoggingOutputStream.java:58)
    	at java.base/java.io.OutputStream.write(OutputStream.java:164)
    	at java.base/java.io.PrintStream.implWrite(PrintStream.java:642)
    	at java.base/java.io.PrintStream.write(PrintStream.java:622)
    	at java.base/sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:313)
    	at java.base/sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:409)
    	at java.base/sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:414)
    	at java.base/sun.nio.cs.StreamEncoder.lockedFlush(StreamEncoder.java:218)
    	at java.base/sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:205)
    	at java.base/java.io.OutputStreamWriter.flush(OutputStreamWriter.java:263)
    	at java.base/java.io.BufferedWriter.implFlush(BufferedWriter.java:372)
    	at java.base/java.io.BufferedWriter.flush(BufferedWriter.java:359)
    	at java.base/java.io.PrintWriter.implNewLine(PrintWriter.java:650)
    	at java.base/java.io.PrintWriter.newLine(PrintWriter.java:640)
    	at java.base/java.io.PrintWriter.println(PrintWriter.java:799)
    	at java.base/java.io.PrintWriter.println(PrintWriter.java:997)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.LowLevelLogUtil.log(LowLevelLogUtil.java:44)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.LowLevelLogUtil.logException(LowLevelLogUtil.java:55)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.EnvironmentPropertySource.logException(EnvironmentPropertySource.java:43)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.EnvironmentPropertySource.containsProperty(EnvironmentPropertySource.java:101)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil$Environment.get(PropertiesUtil.java:513)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil$Environment.access$200(PropertiesUtil.java:434)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil.getStringProperty(PropertiesUtil.java:382)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil.getBooleanProperty(PropertiesUtil.java:169)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.status.StatusLogger.isDebugPropertyEnabled(StatusLogger.java:143)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.status.StatusLogger.isEnabled(StatusLogger.java:426)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.status.StatusLogger.isEnabled(StatusLogger.java:327)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1982)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:740)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.appender.DefaultErrorHandler.error(DefaultErrorHandler.java:61)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.appenderErrorHandlerMessage(AppenderControl.java:118)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.isRecursiveCall(AppenderControl.java:110)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.shouldSkip(AppenderControl.java:93)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:86)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:675)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:633)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:616)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:552)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.Logger.log(Logger.java:161)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2205)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2159)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2142)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2017)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1983)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.log(AbstractLogger.java:1652)
    	at org.elasticsearch.server@8.5.0-SNAPSHOT/org.elasticsearch.common.logging.LoggingOutputStream.log(LoggingOutputStream.java:108)
    	at org.elasticsearch.server@8.5.0-SNAPSHOT/org.elasticsearch.common.logging.LoggingOutputStream.flush(LoggingOutputStream.java:93)
    	at org.elasticsearch.server@8.5.0-SNAPSHOT/org.elasticsearch.common.logging.LoggingOutputStream.write(LoggingOutputStream.java:58)
    	at java.base/java.io.OutputStream.write(OutputStream.java:164)
    	at java.base/java.io.PrintStream.implWrite(PrintStream.java:642)
    	at java.base/java.io.PrintStream.write(PrintStream.java:622)
    	at java.base/sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:313)
    	at java.base/sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:409)
    	at java.base/sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:414)
    	at java.base/sun.nio.cs.StreamEncoder.lockedFlush(StreamEncoder.java:218)
    	at java.base/sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:205)
    	at java.base/java.io.OutputStreamWriter.flush(OutputStreamWriter.java:263)
    	at java.base/java.io.BufferedWriter.implFlush(BufferedWriter.java:372)
    	at java.base/java.io.BufferedWriter.flush(BufferedWriter.java:359)
    	at java.base/java.io.PrintWriter.implNewLine(PrintWriter.java:650)
    	at java.base/java.io.PrintWriter.newLine(PrintWriter.java:640)
    	at java.base/java.io.PrintWriter.println(PrintWriter.java:799)
    	at java.base/java.io.PrintWriter.println(PrintWriter.java:997)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.LowLevelLogUtil.log(LowLevelLogUtil.java:44)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.LowLevelLogUtil.logException(LowLevelLogUtil.java:55)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.EnvironmentPropertySource.logException(EnvironmentPropertySource.java:43)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.EnvironmentPropertySource.containsProperty(EnvironmentPropertySource.java:101)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil$Environment.get(PropertiesUtil.java:513)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil$Environment.access$200(PropertiesUtil.java:434)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil.getStringProperty(PropertiesUtil.java:382)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.util.PropertiesUtil.getBooleanProperty(PropertiesUtil.java:169)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.status.StatusLogger.isDebugPropertyEnabled(StatusLogger.java:143)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.status.StatusLogger.isEnabled(StatusLogger.java:426)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.status.StatusLogger.isEnabled(StatusLogger.java:348)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1906)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.warn(AbstractLogger.java:2731)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.lookup.SystemPropertiesLookup.lookup(SystemPropertiesLookup.java:46)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.lookup.StrLookup.evaluate(StrLookup.java:119)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.lookup.Interpolator.evaluate(Interpolator.java:190)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.lookup.StrSubstitutor.resolveVariable(StrSubstitutor.java:1183)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.lookup.StrSubstitutor.substitute(StrSubstitutor.java:1098)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.lookup.StrSubstitutor.substitute(StrSubstitutor.java:974)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.lookup.StrSubstitutor.replaceIn(StrSubstitutor.java:915)
    	at log4j2.ecs.layout@1.2.0/co.elastic.logging.log4j2.EcsLayout.serializeAdditionalFieldsAndMDC(EcsLayout.java:162)
    	at log4j2.ecs.layout@1.2.0/co.elastic.logging.log4j2.EcsLayout.toText(EcsLayout.java:135)
    	at log4j2.ecs.layout@1.2.0/co.elastic.logging.log4j2.EcsLayout.encode(EcsLayout.java:115)
    	at log4j2.ecs.layout@1.2.0/co.elastic.logging.log4j2.EcsLayout.encode(EcsLayout.java:59)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.directEncodeEvent(AbstractOutputStreamAppender.java:215)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.tryAppend(AbstractOutputStreamAppender.java:208)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:199)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:301)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:161)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:134)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:125)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:89)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:675)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:633)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:616)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:552)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
    	at org.apache.logging.log4j.core@8.5.0-SNAPSHOT/org.apache.logging.log4j.core.Logger.log(Logger.java:161)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2205)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2159)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2142)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2017)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1983)
    	at org.apache.logging.log4j@2.18.0/org.apache.logging.log4j.spi.AbstractLogger.error(AbstractLogger.java:750)
    	at org.elasticsearch.server@8.5.0-SNAPSHOT/org.elasticsearch.bootstrap.ElasticsearchUncaughtExceptionHandler.onNonFatalUncaught(ElasticsearchUncaughtExceptionHandler.java:60)
    	at org.elasticsearch.server@8.5.0-SNAPSHOT/org.elasticsearch.bootstrap.ElasticsearchUncaughtExceptionHandler.uncaughtException(ElasticsearchUncaughtExceptionHandler.java:45)
    	at java.base/java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:701)
    	at java.base/java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:696)
    	at java.base/java.lang.Thread.dispatchUncaughtException(Thread.java:3007)

This looks like a recursive exception - an exception thrown whilst trying to log an exception

This is also logged:

    process reaper (pid 39106) ERROR Recursive call to appender rolling

    
libs/secure-sm/src/main/java/org/elasticsearch/secure_sm/SecureSM.java
private static final Permission MODIFY_THREAD_PERMISSION = new RuntimePermission("modifyThread");
    private static final Permission MODIFY_ARBITRARY_THREAD_PERMISSION = new ThreadPermission("modifyArbitraryThread");
    
    private static boolean isInnocuousThread(Thread t) {
        final Class<?> c = t.getClass();
        return c.getModule() == Object.class.getModule() && c.getName().equals("jdk.internal.misc.InnocuousThread");
    }
    protected void checkThreadAccess(Thread t) {
        Objects.requireNonNull(t);
        
        checkPermission(MODIFY_THREAD_PERMISSION);
        
        final ThreadGroup source = Thread.currentThread().getThreadGroup();
        final ThreadGroup target = t.getThreadGroup();
        if (target == null) {
            return;    
        } else if (source.parentOf(target) == false && isInnocuousThread(t) == false) {
            checkPermission(MODIFY_ARBITRARY_THREAD_PERMISSION);
        }
    }
    private static final Permission MODIFY_THREADGROUP_PERMISSION = new RuntimePermission("modifyThreadGroup");
    private static final Permission MODIFY_ARBITRARY_THREADGROUP_PERMISSION = new ThreadPermission("modifyArbitraryThreadGroup");
    protected void checkThreadGroupAccess(ThreadGroup g) {
        Objects.requireNonNull(g);
        
        checkPermission(MODIFY_THREADGROUP_PERMISSION);
        
        final ThreadGroup source = Thread.currentThread().getThreadGroup();
        final ThreadGroup target = g;
        if (source == null) {