Skip to content

Possible Memory Leak in StatusLogger’s ConcurrentLinkedQueue #3511

@ByteExceptionM

Description

@ByteExceptionM

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.

Image
Image
Image

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:

  1. Start a Minecraft server using Log4j 2.22.1.
  2. Run the server under normal operational load (many background log events).
  3. Leave it running for several hours or days.
  4. Generate a heap dump and analyze memory usage.
  5. If affected, StatusLogger$BoundedQueue will hold millions of ConcurrentLinkedQueue$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.

Metadata

Metadata

Assignees

Labels

apiAffects the public APIinvalid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions