Hardens PropertiesUtil against recursive property sources#3263
Conversation
As showed in #3252, Spring's `JndiPropertySource` not only can throw exceptions, but can also perform logging calls. Such a call causes a recursive call to `PropertiesUtil.getProperty("log4j2.flowMessageFactory"`) and a `StackOverflowException` in the best scenario. The worst scenario includes a deadlock. This PR: - Moves the creation of the default `MessageFactory` and `FlowMessageFactory` to the static initializer of `LoggerContext`. This should be close enough to the pre-2.23.0 location in `AbstractLogger`. The `LoggerContext` class is usually initialized, before Spring Boot adds its property sources to `PropertiesUtil`. - Adds a check to `PropertiesUtil` to ignore recursive calls. Closes #3252.
The constructor is effectively package-private, since it has a package-private class (`AsyncLoggerDisruptor`) in its signature.
|
Hi @ppkarwasz, Can you please consider change back AsyncLogger constructor package-private access back to public? I've extended AsyncLogger class with the same package name to build a customized AsyncLogger and use reflection to initial customized AsyncLogger. This code was working for more than 7 years and blocked in 2.24.3 with this PR code change. Thanks, |
|
Hi @sundaybluesky,
Sure, please open a new feature request. In the new feature request, can you explain how are you using
That is the problem with using reflection to access private methods or classes like Note: As far as I understand you called the constructor of |
|
Hi @ppkarwasz , Thanks for you quick response. I created #3527 to track this issue, please help to take a look. Regards, |
As showed in #3252, Spring's
JndiPropertySourcenot only can throw exceptions, but can also perform logging calls. Such a call causes a recursive call toPropertiesUtil.getProperty("log4j2.flowMessageFactory") and aStackOverflowExceptionin the best scenario. The worst scenario includes a deadlock.This PR:
MessageFactoryandFlowMessageFactoryto the static initializer ofLoggerContext. This should be close enough to the pre-2.23.0 location inAbstractLogger. TheLoggerContextclass is usually initialized, before Spring Boot adds its property sources toPropertiesUtil.PropertiesUtilto ignore recursive calls.Closes #3252.