[ISSUE #13940]: Eliminate ClassUnload during config reload using Configuration.initialize()#14000
Conversation
|
Thanks for your this PR. 🙏 感谢您提交的PR。 🙏 |
|
It's looks great. But there is the question: Do you test the version ranges of this changes? Before merged I want you to test the version ranges of log4j2. |
Yes, I have tested the version ranges of Log4j2. I ran the adapter module tests (log4j2-adapter) against multiple Log4j2 versions by overriding the log4j.version Maven property: All tests passed successfully across the following versions: Log4j2 2.7: ✅ 8/8 passed (Minimum supported version) I verified this by checking the method signature across all versions using javap, and all versions (2.7, 2.11.1, 2.14.1, 2.17.2, 2.24.3) have the public void initialize(); method. All other APIs used (Configuration.getAppenders(), addAppender(), addLogger(), LoggerContext.updateLoggers()) are part of the Log4j2 core interface since 2.0+. Conclusion: This change is backward compatible with all supported Log4j2 versions (2.7+) and introduces no breaking changes. |
|
|
Great |
|
@JGoP-L Welcome submit similar PR to v2.x-develop also. BTW, would you mind provider your dingtalk number? We would like invite you into nacos contributor group. |
Sure, no problem. My DingTalk ID is m8s_6u8vg21n1. And I'd be glad to submit similar PRs to the v2.x-develop branch. |
…lize() Fixes alibaba#13940 - Apply official PR alibaba#14000 fix to v2.x-develop branch This commit applies the official fix from alibaba/nacos PR alibaba#14000 (commit 90747d4) to resolve ClassUnload issues during Log4j2 configuration reload. Key changes: 1. Add NacosLog4j2Configurator class using Configuration.initialize() instead of Configuration.start() to avoid plugin reinitialization 2. Refactor Log4J2NacosLoggingAdapter to delegate to new configurator 3. Remove deprecated helper methods and simplify test implementation 4. Add thread-safe double-checked locking pattern 5. Additively merge Nacos config without replacing user's logging setup The fix follows framework-compliant pattern similar to Logback adapter. Adapted from: alibaba#14000 Original commit: 90747d4
…lize() (#14025) Fixes #13940 - Apply official PR #14000 fix to v2.x-develop branch This commit applies the official fix from alibaba/nacos PR #14000 (commit 90747d4) to resolve ClassUnload issues during Log4j2 configuration reload. Key changes: 1. Add NacosLog4j2Configurator class using Configuration.initialize() instead of Configuration.start() to avoid plugin reinitialization 2. Refactor Log4J2NacosLoggingAdapter to delegate to new configurator 3. Remove deprecated helper methods and simplify test implementation 4. Add thread-safe double-checked locking pattern 5. Additively merge Nacos config without replacing user's logging setup The fix follows framework-compliant pattern similar to Logback adapter. Adapted from: #14000 Original commit: 90747d4
[ISSUE #13940] Fix ClassUnload issue by replacing Configuration.start() with initialize()
What is the purpose of the change
Fix Issue #13940: Resolve the ClassUnload problem during Log4j2 configuration reload.
Root Cause: When Nacos reloads the Log4j2 logging configuration, calling
Configuration.start()triggersPluginManager.loadPlugins(), which causes 150-200 ClassUnload events per reload. This results in significant GC pressure and performance degradation.Solution: Replace
Configuration.start()withConfiguration.initialize()to avoid triggering the plugin manager's plugin discovery and loading process. Theinitialize()method only initializes the configuration without loading plugins, which is more appropriate for merging configurations additively.Key Benefits:
Brief changelog
New Files
Configuration.initialize()instead ofstart()to avoid plugin reloadingModified Files
Log4J2NacosLoggingAdapter.java
configuration.start()withconfigurator.configure(loggerContext, configUri)Log4j2NacosLoggingPropertiesHolder.java
getProperties()getter method to support external property queriesLog4J2NacosLoggingAdapterTest.java
Performance Improvements
Verifying this change
Unit Tests
Run the following command to verify all tests pass: