apache / apache/curator

[Bug] Potential OOM in ThreadUtils due to unbounded newFixedThreadPool

Open
#1,283 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
3.2k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

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)
);
}

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.