This is an automated email from the ASF dual-hosted git repository.
heliang666s pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git
The following commit(s) were added to refs/heads/3.3 by this push:
new b6f2a0f7fb Fix: Add warning log when using unbounded queue in
FixedThreadPool (Issue #15969) (#15984)
b6f2a0f7fb is described below
commit b6f2a0f7fb6622f681e286341d9790feb771db0b
Author: Shivvani Ramadugu <[email protected]>
AuthorDate: Mon Jan 12 08:45:21 2026 +0530
Fix: Add warning log when using unbounded queue in FixedThreadPool (Issue
#15969) (#15984)
---
.../common/threadpool/support/fixed/FixedThreadPool.java | 12 ++++++++++++
.../common/threadpool/support/fixed/FixedThreadPoolTest.java | 11 +++++++++++
2 files changed, 23 insertions(+)
diff --git
a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java
b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java
index 137f6af362..de39107198 100644
---
a/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java
+++
b/dubbo-common/src/main/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPool.java
@@ -17,6 +17,8 @@
package org.apache.dubbo.common.threadpool.support.fixed;
import org.apache.dubbo.common.URL;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
+import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.threadlocal.NamedInternalThreadFactory;
import org.apache.dubbo.common.threadpool.MemorySafeLinkedBlockingQueue;
import org.apache.dubbo.common.threadpool.ThreadPool;
@@ -35,6 +37,7 @@ import static
org.apache.dubbo.common.constants.CommonConstants.DEFAULT_THREAD_N
import static org.apache.dubbo.common.constants.CommonConstants.QUEUES_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.THREADS_KEY;
import static
org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
+import static
org.apache.dubbo.common.constants.LoggerCodeConstants.COMMON_UNEXPECTED_EXCEPTION;
/**
* Creates a thread pool that reuses a fixed number of threads
@@ -43,6 +46,8 @@ import static
org.apache.dubbo.common.constants.CommonConstants.THREAD_NAME_KEY;
*/
public class FixedThreadPool implements ThreadPool {
+ private static final ErrorTypeAwareLogger logger =
LoggerFactory.getErrorTypeAwareLogger(FixedThreadPool.class);
+
@Override
public Executor getExecutor(URL url) {
String name =
@@ -56,6 +61,13 @@ public class FixedThreadPool implements ThreadPool {
blockingQueue = new SynchronousQueue<>();
} else if (queues < 0) {
blockingQueue = new MemorySafeLinkedBlockingQueue<>();
+ logger.warn(
+ COMMON_UNEXPECTED_EXCEPTION,
+ "",
+ "",
+ "FixedThreadPool created with an unbounded queue (queues <
0). "
+ + "This may lead to OutOfMemoryError under high
load. "
+ + "Consider configuring a positive integer for
'queues'.");
} else {
blockingQueue = new LinkedBlockingQueue<>(queues);
}
diff --git
a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java
b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java
index a12bcc0f3f..cc19213346 100644
---
a/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java
+++
b/dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/support/fixed/FixedThreadPoolTest.java
@@ -18,6 +18,7 @@ package org.apache.dubbo.common.threadpool.support.fixed;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.threadlocal.InternalThread;
+import org.apache.dubbo.common.threadpool.MemorySafeLinkedBlockingQueue;
import org.apache.dubbo.common.threadpool.ThreadPool;
import org.apache.dubbo.common.threadpool.support.AbortPolicyWithReport;
@@ -81,4 +82,14 @@ class FixedThreadPoolTest {
ThreadPoolExecutor executor = (ThreadPoolExecutor)
threadPool.getExecutor(url);
assertThat(executor.getQueue(),
Matchers.<BlockingQueue<Runnable>>instanceOf(LinkedBlockingQueue.class));
}
+
+ @Test
+ void testNegativeQueuesCreateUnboundedQueue() {
+ URL url = URL.valueOf("dubbo://10.20.130.230:20880/context/path?" +
QUEUES_KEY + "=-1");
+ ThreadPool threadPool = new FixedThreadPool();
+ ThreadPoolExecutor executor = (ThreadPoolExecutor)
threadPool.getExecutor(url);
+ assertThat(
+ executor.getQueue(),
Matchers.<BlockingQueue<Runnable>>instanceOf(MemorySafeLinkedBlockingQueue.class));
+ assertThat(executor.getQueue().remainingCapacity(),
is(Integer.MAX_VALUE));
+ }
}