-
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
Broken logger initialization in 2.24.1 #3143
Comments
Thank you for the report. The |
We hit a similar issues at Apache POI, there it happens reproducibly if log4j-core 2.24.0 and log4j-api 2.24.1 are used. Reproducer: Run "./gradlew runWriteFile -PpoiVersion=5.4.0" in a checkout of https://github.com/centic9/poi-reproduce This version-mismatch happens if a library like Apache POI upgrades "api" to the latest version, but projects using it do not upgrade log4j-core along the way. This is likely a common situation.
Edit: I verified with current 2.25.0-SNAPSHOT and this problem still reproduces, so I reported #3196 to discuss this as a separate issue. |
@ppkarwasz when the version 2.25 will be released? And is 2.23 devoid of this bug? |
As far as I couuld reproduce, it will not be fixed by current 2.25.0-SNAPSHOT, therefore I created bug #3196 for the issue with mixed "api" and "core" versions. |
Removes weak references to `Logger`s in `LoggerRepository`. The usage of weak references in `LoggerRepository` might cause `null` to be returned by `LogManager.getLogger()` of all Log4j Core versions up to `2.24.1`. Versions of Log4j API up to `2.24.0` did hold **hard** references to all the registered loggers, so the change will not alter the previous behavior. This PR also inverts the order of the `String` and `MessageFactory` keys to the `LoggerRepository` multi-map to limit the number of internal maps. The external map is a `WeakHashMap` to allow logger-specific message factories to be GC-ed. Closes #3143.
Removes weak references to `Logger`s in `LoggerRepository`. The usage of weak references in `LoggerRepository` might cause `null` to be returned by `LogManager.getLogger()` of all Log4j Core versions up to `2.24.1`. Versions of Log4j API up to `2.24.0` did hold **hard** references to all the registered loggers, so the change will not alter the previous behavior. This PR also inverts the order of the `String` and `MessageFactory` keys to the `LoggerRepository` multi-map to limit the number of internal maps. The external map is a `WeakHashMap` to allow logger-specific message factories to be GC-ed. Closes #3143.
Thanks for the change @ppkarwasz when can we expect the release for the same. |
I am planning a As always, you are invited to review PRs, run release candidates in your tests and vote on releases. A motivated |
Removes weak references to `Logger`s in `LoggerRepository`. The usage of weak references in `LoggerRepository` might cause `null` to be returned by `LogManager.getLogger()` of all Log4j Core versions up to `2.24.1`. Versions of Log4j API up to `2.24.0` did hold **hard** references to all the registered loggers, so the change will not alter the previous behavior. This PR also inverts the order of the `String` and `MessageFactory` keys to the `LoggerRepository` multi-map to limit the number of internal maps. The external map is a `WeakHashMap` to allow logger-specific message factories to be GC-ed. Closes apache#3143.
) This is a port of #3199 to the 2.24.x branch. Removes weak references to `Logger`s in `LoggerRepository`. The usage of weak references in `LoggerRepository` might cause `null` to be returned by `LogManager.getLogger()` of all Log4j Core versions up to `2.24.1`. Versions of Log4j API up to `2.24.0` did hold **hard** references to all the registered loggers, so the change will not alter the previous behavior. This PR also inverts the order of the `String` and `MessageFactory` keys to the `LoggerRepository` multi-map to limit the number of internal maps. The external map is a `WeakHashMap` to allow logger-specific message factories to be GC-ed. Closes #3143. Co-authored-by: Volkan Yazıcı <[email protected]>
) This is a port of #3199 to the 2.24.x branch. Removes weak references to `Logger`s in `LoggerRepository`. The usage of weak references in `LoggerRepository` might cause `null` to be returned by `LogManager.getLogger()` of all Log4j Core versions up to `2.24.1`. Versions of Log4j API up to `2.24.0` did hold **hard** references to all the registered loggers, so the change will not alter the previous behavior. This PR also inverts the order of the `String` and `MessageFactory` keys to the `LoggerRepository` multi-map to limit the number of internal maps. The external map is a `WeakHashMap` to allow logger-specific message factories to be GC-ed. Closes #3143. Co-authored-by: Volkan Yazıcı <[email protected]>
Details: https://lists.apache.org/thread/whovnwgvksgr6v5c3195nclg6sk450my Actually this does not affect OFBiz current version of Log4j. OFBiz uses 2.20.0 and, according to apache/logging-log4j2#3143 (comment) the error concerns only 2.24.1. But while at it better update our version only backporting to 24.09 Conflicts handled by hand
Details: https://lists.apache.org/thread/whovnwgvksgr6v5c3195nclg6sk450my Actually this does not affect OFBiz current version of Log4j. OFBiz uses 2.20.0 and, according to apache/logging-log4j2#3143 (comment) the error concerns only 2.24.1. But while at it better update our version only backporting to 24.09
### What changes were proposed in this pull request? The pr aims to upgrade log4j2 from `2.24.1` to `2.24.2`. ### Why are the changes needed? - The full release notes: https://github.com/apache/logging-log4j2/releases/tag/rel%2F2.24.2 - This release fixes a critical bug in Log4j API initialization code, which can cause LogManager.getLogger() to return null under certain conditions. See apache/logging-log4j2#3143 for details. Fix key removal issues in Thread Context (apache/logging-log4j2#3048) Use hard references to Loggers in LoggerRegistry. (apache/logging-log4j2#3143) Fix ArrayIndexOutOfBoundsException in JSON Template Layout truncated exception resolver (apache/logging-log4j2#3216) ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass GA. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #48945 from panbingkun/SPARK-50400. Authored-by: panbingkun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
Description
LoggerContext / LoggerRegistry don't play well together in using weak references, which can result in a
null
logger if the GC kicks in at a bad timing.Configuration
Version: 2.24.1
Operating system: Linux / macOS
JDK: 21.0.4
Logs
Reproduction
LoggerContext
keeps a local reference tonewLogger
, but this isn't safe to keep a reference (see below).LoggerRegistry.putIfAbsent
takes the instance and creates aWeakReference
from it.getLogger
call returningnull
https://docs.oracle.com/javase/specs/jls/se21/html/jls-12.html#jls-12.6.1
Fix
#2936 should fix this, but is currently unreleased.
Reference.reachabilityFence
would also fix this, but is JDK 9+ only.See also: https://shipilev.net/jvm/anatomy-quarks/8-local-var-reachability/
The text was updated successfully, but these errors were encountered: