Skip to content

[Bug] Potential OOM in ThreadUtils due to unbounded newFixedThreadPool #1283

@QiuYucheng2003

Description

@QiuYucheng2003

Problem Description
The org.apache.curator.utils.ThreadUtils.newFixedThreadPool method internally wraps Executors.newFixedThreadPool:
// ThreadUtils.java
public static ExecutorService newFixedThreadPool(int qty, String processName) {
return Executors.newFixedThreadPool(qty, newThreadFactory(processName));
}

Root Cause
The JDK's Executors.newFixedThreadPool uses a LinkedBlockingQueue with a default capacity of Integer.MAX_VALUE. This creates an unbounded queue.

Impact
In distributed scenarios (e.g., high ZooKeeper server latency or connection storms), background tasks and callbacks generated by Curator clients will accumulate indefinitely in this queue. Since there is no backpressure mechanism (queue capacity limit), this eventually leads to java.lang.OutOfMemoryError: Java heap space.

Suggested Fix
Replace the Executors factory method with a direct ThreadPoolExecutor construction using a bounded queue (e.g., ArrayBlockingQueue) and an appropriate RejectedExecutionHandler.

// Proposed change
public static ExecutorService newFixedThreadPool(int qty, String processName) {
return new ThreadPoolExecutor(
qty, qty,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<>(10000), // Bounded capacity
newThreadFactory(processName)
);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions