This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 267c33b474 fix(common): bound shared executor workers by default
(#7232)
267c33b474 is described below
commit 267c33b4742b0200fad5949f031c06b2cfb27e84
Author: Liming Deng <[email protected]>
AuthorDate: Wed Sep 30 11:54:10 2026 +0800
fix(common): bound shared executor workers by default (#7232)
---
.../apache/shenyu/common/config/ShenyuConfig.java | 8 +++--
.../shenyu/common/config/ShenyuConfigTest.java | 12 ++++++++
.../ShenyuThreadPoolConfigurationTest.java | 34 ++++++++++++++++++++++
3 files changed, 51 insertions(+), 3 deletions(-)
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
index 8b83e1d406..ac3e74d385 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/config/ShenyuConfig.java
@@ -24,6 +24,7 @@ import org.apache.shenyu.common.constant.Constants;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;
@@ -1664,9 +1665,10 @@ public class ShenyuConfig {
private Integer corePoolSize = 200;
/**
- * the maximum number of threads to allow in the thread pool.
+ * The maximum number of threads to allow in the thread pool.
+ * Defaults to corePoolSize so the eager queue cannot create unbounded
workers.
*/
- private Integer maximumPoolSize = Integer.MAX_VALUE;
+ private Integer maximumPoolSize;
/**
* when the number of threads is greater than the core,
@@ -1753,7 +1755,7 @@ public class ShenyuConfig {
* @return the shared thread pool name prefix
*/
public Integer getMaximumPoolSize() {
- return maximumPoolSize;
+ return Objects.isNull(maximumPoolSize) ? corePoolSize :
maximumPoolSize;
}
/**
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/config/ShenyuConfigTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/config/ShenyuConfigTest.java
index 4f9bdf58a6..961c494b2a 100644
---
a/shenyu-common/src/test/java/org/apache/shenyu/common/config/ShenyuConfigTest.java
+++
b/shenyu-common/src/test/java/org/apache/shenyu/common/config/ShenyuConfigTest.java
@@ -37,6 +37,18 @@ public class ShenyuConfigTest {
private final ShenyuConfig config = new ShenyuConfig();
+ @Test
+ public void testSharedPoolMaximumDefaultsToCoreSize() {
+ ShenyuConfig.SharedPool pool = config.getSharedPool();
+ assertEquals(200, pool.getMaximumPoolSize());
+ pool.setCorePoolSize(300);
+ assertEquals(300, pool.getMaximumPoolSize());
+ pool.setMaximumPoolSize(400);
+ assertEquals(400, pool.getMaximumPoolSize());
+ pool.setCorePoolSize(350);
+ assertEquals(400, pool.getMaximumPoolSize());
+ }
+
/**
* test of shenyuConfig.
*
diff --git
a/shenyu-web/src/test/java/org/apache/shenyu/web/configuration/ShenyuThreadPoolConfigurationTest.java
b/shenyu-web/src/test/java/org/apache/shenyu/web/configuration/ShenyuThreadPoolConfigurationTest.java
index 76e6d2ff4c..3f9bceefbf 100644
---
a/shenyu-web/src/test/java/org/apache/shenyu/web/configuration/ShenyuThreadPoolConfigurationTest.java
+++
b/shenyu-web/src/test/java/org/apache/shenyu/web/configuration/ShenyuThreadPoolConfigurationTest.java
@@ -33,6 +33,10 @@ import
org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextClosedEvent;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -92,6 +96,36 @@ public class ShenyuThreadPoolConfigurationTest {
assertNotNull(shenyuThreadPoolConfiguration.shenyuThreadPoolExecutor(shenyuConfig,
new TestObjectProvider<>(new MemorySafeTaskQueue<>(Constants.THE_256_MB))));
}
+ @Test
+ public void testSharedPoolQueuesAtDefaultMaximum() throws
InterruptedException {
+ ShenyuConfig config = new ShenyuConfig();
+ config.getSharedPool().setCorePoolSize(2);
+ ShenyuThreadPoolExecutor executor =
shenyuThreadPoolConfiguration.shenyuThreadPoolExecutor(config,
+ new TestObjectProvider<>(new MemorySafeTaskQueue<>(1)));
+ CountDownLatch started = new CountDownLatch(2);
+ CountDownLatch release = new CountDownLatch(1);
+ Runnable blockingTask = () -> {
+ started.countDown();
+ try {
+ release.await();
+ } catch (InterruptedException exception) {
+ Thread.currentThread().interrupt();
+ }
+ };
+ try {
+ executor.execute(blockingTask);
+ executor.execute(blockingTask);
+ assertTrue(started.await(5, TimeUnit.SECONDS));
+ executor.execute(() -> { });
+ assertEquals(2, executor.getPoolSize());
+ assertEquals(1, executor.getQueue().size());
+ } finally {
+ release.countDown();
+ executor.shutdownNow();
+ assertTrue(executor.awaitTermination(5, TimeUnit.SECONDS));
+ }
+ }
+
@Test
public void testShenyuThreadPoolExecutorDestructor() {
ShenyuThreadPoolConfiguration.ShenyuThreadPoolExecutorDestructor
shenyuThreadPoolExecutorDestructor =