-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Description
Log4j2's StatusLogger$BoundedQueue
is causing a memory leak, where millions of ConcurrentLinkedQueue$Node
instances are being retained, leading to extreme memory usage.
A heap dump analysis reveals:
- 210,815,632
ConcurrentLinkedQueue$Node
instances consuming 4.7 GB of RAM. - 105,409,426
ConcurrentLinkedQueue
instances consuming 2.4 GB of RAM.
This issue occurs on a single node running Log4j 2.22.1, and has only started happening recently, without any noticeable log warnings or errors.
Configuration
- Version: Log4j 2.22.1
- Operating system: Private Docker image, based on itzg/minecraft-server
- JDK: JDK 21.0.6+7
- Container environment: Running within a Docker container
Logs
There are no noticeable errors or stack traces. The issue was identified through heap dump analysis, which shows that StatusLogger$BoundedQueue
is retaining a massive number of ConcurrentLinkedQueue$Node
instances, leading to a memory leak of over 4.9 GB.
Reproduction
The exact trigger is unknown, but the issue was observed on a high-load Minecraft server using Log4j 2.22.1. To reproduce:
- Start a Minecraft server using Log4j 2.22.1.
- Run the server under normal operational load (many background log events).
- Leave it running for several hours or days.
- Generate a heap dump and analyze memory usage.
- If affected,
StatusLogger$BoundedQueue
will hold millions ofConcurrentLinkedQueue$Node
instances, consuming several gigabytes of RAM.
I found that Log4j2 uses a ConcurrentLinkedQueue
in the StatusLogger
implementation: StatusLogger.java, line 521
This could be the reason for the uncontrolled memory growth, as the queue might not be properly cleared or bounded under certain conditions.