-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConcurrentModificationException in LoggerContext due to race condition #3234
Comments
I'd suggest fixing this by making |
The `InternalLoggerRegistry` implementation introduced in version `2.24.2` did not return a copy of the registry, when `InternalLoggerRegistry.getLoggers()` was called. This could lead to a `ConcurrentModificationException` if a thread creates a new logger, while another thread calls `LoggerContext.updateLoggers()`. Closes #3234
Nice catch! 💯 |
I'm not certain this is related, but we're seeing what looks like a deadlock around
|
I think it is unrelated, but looking at the stack trace it is almost definitely a dead lock. Do you know what is the other lock (
|
@ppkarwasz unfortunately we didn't deep dive |
@ppkarwasz I have opened #3252 for the apparent deadlock - thanks! |
because of the apache/logging-log4j2#3234
because of the apache/logging-log4j2#3234
I see that we ran into the same issue -- I raised it as #3283 before realizing this issue already existed. |
Thank you @ppkarwasz, was just about to report this! 🙈 |
…tionException in LoggerContext ### Why are the changes needed? Bump the log4j version to fix below issue: ``` 2025-03-04 22:27:58.291 WARN [main-SendThread(xxxx:2181)] org.apache.kyuubi.shaded.zookeeper.ClientCnxn: Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect : java.lang.ExceptionInInitializerError at org.apache.log4j.Logger.getLogger(Logger.java:35) at org.apache.kyuubi.shaded.zookeeper.Login.<init>(Login.java:44) at org.apache.kyuubi.shaded.zookeeper.client.ZooKeeperSaslClient.createSaslClient(ZooKeeperSaslClient.java:228) at org.apache.kyuubi.shaded.zookeeper.client.ZooKeeperSaslClient.<init>(ZooKeeperSaslClient.java:131) at org.apache.kyuubi.shaded.zookeeper.ClientCnxn$SendThread.startConnect(ClientCnxn.java:990) at org.apache.kyuubi.shaded.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1042) Caused by: java.util.ConcurrentModificationException at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1657) at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:647) at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:272) at java.util.WeakHashMap$ValueSpliterator.forEachRemaining(WeakHashMap.java:1216) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472) at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:485) at org.apache.logging.log4j.core.LoggerContext.updateLoggers(LoggerContext.java:776) at org.apache.logging.log4j.core.LoggerContext.updateLoggers(LoggerContext.java:766) at org.apache.logging.log4j.core.config.Configurator.setLevel(Configurator.java:379) at org.apache.logging.log4j.core.config.Configurator.setLevel(Configurator.java:344) at org.apache.log4j.legacy.core.CategoryUtil.setLevel(CategoryUtil.java:131) at org.apache.log4j.Category.setLevel(Category.java:643) at org.apache.log4j.Category.setLevel(Category.java:638) at org.apache.log4j.spi.RootLogger.setLevel(RootLogger.java:60) at org.apache.log4j.spi.RootLogger.<init>(RootLogger.java:39) at org.apache.log4j.LogManager.<clinit>(LogManager.java:70) ... 6 more ``` It is fixed in https://github.com/apache/logging-log4j2/releases/tag/rel%2F2.24.3 apache/logging-log4j2#3234 ### How was this patch tested? Existing GA. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #6960 from turboFei/log4j_version. Closes #6960 48b076c [Wang, Fei] Upgrade log4j version to 2.24.3 Authored-by: Wang, Fei <[email protected]> Signed-off-by: Cheng Pan <[email protected]>
2.24.2 version of log4j introduces an exception: apache/logging-log4j2#3234, causing falkiness in test cases. Removing this will use the version used in openSearch core (currently 2.21.0 Signed-off-by: rithin-pullela-aws <[email protected]>
2.24.2 version of log4j introduces an exception: apache/logging-log4j2#3234, causing falkiness in test cases. Removing this will use the version used in openSearch core (currently 2.21.0 Signed-off-by: rithin-pullela-aws <[email protected]>
2.24.2 version of log4j introduces an exception: apache/logging-log4j2#3234, causing falkiness in test cases. Removing this will use the version used in openSearch core (currently 2.21.0 Signed-off-by: rithin-pullela-aws <[email protected]>
Description
Presumably due to a1dfa85 my application throws an error when loggers get changed from multiple threads.
This is likely because
InternalLoggerRegistry#getLoggers
does not return a thread-safe stream.Streams are by nature evaluated on the fly, thus still using the values of
loggerRefByNameByMessageFactory
afterreadLock
was unlocked.When multiple threads modify
loggerRefByNameByMessageFactory
, sometimes it errors with the attached error.This happens inconsistently because it's a race condition, but I've been able to get this error a few times.
Configuration
Version: 2.24.2
Operating system: Windows
JDK: openjdk version "21.0.4" 2024-07-16 LTS
Logs
This shows the stream being collected due to the forEach call in
LoggerContext#updateLoggers
, but there being no read lock, therefore causing this race condition.Reproduction
I unfortunately cannot provide an example because I do not have much experience with reproducing race conditions.
The text was updated successfully, but these errors were encountered: