pmk75 opened a new issue, #3551:
URL: https://github.com/apache/logging-log4j2/issues/3551
## Description
LoggerContext.updateLoggers throws a ConcurrentModificationException
randomly when called by javamelody filter initialisation during tomcat startup.
Result is that tomcat is incorrectly started, process is there but does not
serve any request
## Configuration
**Version:** 2.24.2
**Operating system:** Ubuntu 24.04
**JDK:** amazon-corretto-17.0.10.8.1-linux-x64
## Logs
```java
19-Mar-2025 05:35:40.941 SEVERE [main]
org.apache.catalina.core.StandardContext.filterStart Exception starting filter
[javamelody]
java.util.ConcurrentModificationException
at
java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1784)
at
java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
at
java.base/java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:276)
at
java.base/java.util.WeakHashMap$ValueSpliterator.forEachRemaining(WeakHashMap.java:1217)
at
java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at
java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at
java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
at
java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
at
java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at
java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
at
org.apache.logging.log4j.core.LoggerContext.updateLoggers(LoggerContext.java:776)
at
org.apache.logging.log4j.core.LoggerContext.updateLoggers(LoggerContext.java:766)
at
net.bull.javamelody.Log4J2Appender.register(Log4J2Appender.java:86)
at
net.bull.javamelody.FilterContext.initLogs(FilterContext.java:333)
at
net.bull.javamelody.FilterContext.<init>(FilterContext.java:98)
at
net.bull.javamelody.MonitoringFilter.init(MonitoringFilter.java:148)
at
org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:244)
```
## Reproduction
Randomly appears at startup (every 5 to 10 starts)
## Discussion
The related javamelody code is here
https://github.com/javamelody/javamelody/blob/6bb2b275b7dc77cded89ac661352094e10449e16/javamelody-core/src/main/java/net/bull/javamelody/Log4J2Appender.java#L86
And the exception is thrown here
https://github.com/apache/logging-log4j2/blob/3ffaf76fbd893055d8b60e0d1c319676aa58437e/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java#L812
May be it would be safer to wrap the loggerRegistry.getLoggers()
collection, in a separate one such as
```
new ArrayList<>(loggerRegistry.getLoggers()).forEach(....
```
to avoid potential concurrent modification.
Not really sure of the cause and therefore the potential solution.
Did anybody else noticed this issue ?
--
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]