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 8f042f1186 fix(logging): close owned callback executors (#7226)
8f042f1186 is described below

commit 8f042f1186b78ce36066b3576102a3fc88a9474b
Author: Liming Deng <[email protected]>
AuthorDate: Wed Sep 30 12:02:12 2026 +0800

    fix(logging): close owned callback executors (#7226)
---
 .../sls/client/AliyunSlsLogCollectClient.java      | 12 +++++++++---
 .../aliyunsls/AliyunSlsLogCollectClientTest.java   | 22 ++++++++++++++++++++++
 .../lts/client/HuaweiLtsLogCollectClient.java      | 17 +++++++++++------
 .../lts/client/HuaweiLtsLogCollectClientTest.java  | 21 +++++++++++++++++++++
 .../cls/client/TencentClsLogCollectClient.java     | 16 +++++++++++-----
 .../tencentcls/TencentClsLogCollectClientTest.java | 21 +++++++++++++++++++++
 6 files changed, 95 insertions(+), 14 deletions(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/client/AliyunSlsLogCollectClient.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/client/AliyunSlsLogCollectClient.java
index e66418e0ba..ab69e00bfd 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/client/AliyunSlsLogCollectClient.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/main/java/org/apache/shenyu/plugin/aliyun/sls/client/AliyunSlsLogCollectClient.java
@@ -121,9 +121,15 @@ public class AliyunSlsLogCollectClient extends 
AbstractLogConsumeClient<AliyunLo
 
     @Override
     public void close0() throws Exception {
-        if (Objects.nonNull(client)) {
-            client.shutdown();
-            producer.close();
+        try {
+            if (Objects.nonNull(client)) {
+                client.shutdown();
+                producer.close();
+            }
+        } finally {
+            if (Objects.nonNull(threadExecutor)) {
+                threadExecutor.shutdown();
+            }
         }
     }
 
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/test/java/org/apache/shenyu/plugin/aliyun/sls/aliyunsls/AliyunSlsLogCollectClientTest.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/test/java/org/apache/shenyu/plugin/aliyun/sls/aliyunsls/AliyunSlsLogCollectClientTest.java
index 832c5b1235..41cb198117 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/test/java/org/apache/shenyu/plugin/aliyun/sls/aliyunsls/AliyunSlsLogCollectClientTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-aliyun-sls/src/test/java/org/apache/shenyu/plugin/aliyun/sls/aliyunsls/AliyunSlsLogCollectClientTest.java
@@ -29,6 +29,8 @@ import org.junit.jupiter.api.Test;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ThreadPoolExecutor;
+import org.springframework.test.util.ReflectionTestUtils;
 
 /**
  * test cases for AliyunSlsLogCollectClient.
@@ -83,4 +85,24 @@ public class AliyunSlsLogCollectClientTest {
         Assertions.assertEquals(msg, "");
         aliyunSlsLogCollectClient.close();
     }
+
+    @Test
+    public void testCloseShutsDownCallbackExecutorAfterPartialInitialization() 
throws Exception {
+        ThreadPoolExecutor executor = 
org.mockito.Mockito.mock(ThreadPoolExecutor.class);
+        ReflectionTestUtils.setField(aliyunSlsLogCollectClient, 
"threadExecutor", executor);
+        aliyunSlsLogCollectClient.close0();
+        org.mockito.Mockito.verify(executor).shutdown();
+    }
+
+    @Test
+    public void testCloseShutsDownCallbackExecutorWhenProducerFails() throws 
Exception {
+        ThreadPoolExecutor executor = 
org.mockito.Mockito.mock(ThreadPoolExecutor.class);
+        ReflectionTestUtils.setField(aliyunSlsLogCollectClient, 
"threadExecutor", executor);
+        com.aliyun.openservices.aliyun.log.producer.Producer producer = 
org.mockito.Mockito.mock(com.aliyun.openservices.aliyun.log.producer.Producer.class);
+        ReflectionTestUtils.setField(aliyunSlsLogCollectClient, "producer", 
producer);
+        ReflectionTestUtils.setField(aliyunSlsLogCollectClient, "client", 
org.mockito.Mockito.mock(com.aliyun.openservices.log.Client.class));
+        org.mockito.Mockito.doThrow(new IllegalStateException("close 
failed")).when(producer).close();
+        Assertions.assertThrows(IllegalStateException.class, 
aliyunSlsLogCollectClient::close0);
+        org.mockito.Mockito.verify(executor).shutdown();
+    }
 }
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/main/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClient.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/main/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClient.java
index c6e2d0bfc4..8ec3c71d13 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/main/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClient.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/main/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClient.java
@@ -117,12 +117,17 @@ public class HuaweiLtsLogCollectClient extends 
AbstractLogConsumeClient<HuaweiLo
 
     @Override
     public void close0() throws Exception {
-        if (Objects.nonNull(producer)) {
-            try {
-                producer.close();
-
-            } catch (InterruptedException | ProducerException e) {
-                LOG.error("Close producer error.");
+        try {
+            if (Objects.nonNull(producer)) {
+                try {
+                    producer.close();
+                } catch (InterruptedException | ProducerException e) {
+                    LOG.error("Close producer error.");
+                }
+            }
+        } finally {
+            if (Objects.nonNull(threadExecutor)) {
+                threadExecutor.shutdown();
             }
         }
     }
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/test/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClientTest.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/test/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClientTest.java
index f70fa1cd32..5affdc8b1e 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/test/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClientTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-huawei-lts/src/test/java/org/apache/shenyu/plugin/huawei/lts/client/HuaweiLtsLogCollectClientTest.java
@@ -32,6 +32,8 @@ import org.mockito.Mockito;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ThreadPoolExecutor;
+import org.springframework.test.util.ReflectionTestUtils;
 
 public class HuaweiLtsLogCollectClientTest {
     private HuaweiLtsLogCollectClient huaweiLtsLogCollectClient;
@@ -107,4 +109,23 @@ public class HuaweiLtsLogCollectClientTest {
                 HuaweiLogCollectConfig.INSTANCE.getHuaweiLogCollectConfig());
         huaweiLtsLogCollectClient.close();
     }
+
+    @Test
+    public void testCloseShutsDownCallbackExecutorAfterPartialInitialization() 
throws Exception {
+        ThreadPoolExecutor executor = 
org.mockito.Mockito.mock(ThreadPoolExecutor.class);
+        ReflectionTestUtils.setField(huaweiLtsLogCollectClient, 
"threadExecutor", executor);
+        huaweiLtsLogCollectClient.close0();
+        org.mockito.Mockito.verify(executor).shutdown();
+    }
+
+    @Test
+    public void testCloseShutsDownCallbackExecutorWhenProducerFails() throws 
Exception {
+        ThreadPoolExecutor executor = 
org.mockito.Mockito.mock(ThreadPoolExecutor.class);
+        ReflectionTestUtils.setField(huaweiLtsLogCollectClient, 
"threadExecutor", executor);
+        com.huaweicloud.lts.producer.Producer producer = 
org.mockito.Mockito.mock(com.huaweicloud.lts.producer.Producer.class);
+        ReflectionTestUtils.setField(huaweiLtsLogCollectClient, "producer", 
producer);
+        org.mockito.Mockito.doThrow(new IllegalStateException("close 
failed")).when(producer).close();
+        Assertions.assertThrows(IllegalStateException.class, 
huaweiLtsLogCollectClient::close0);
+        org.mockito.Mockito.verify(executor).shutdown();
+    }
 }
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/main/java/org/apache/shenyu/plugin/tencent/cls/client/TencentClsLogCollectClient.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/main/java/org/apache/shenyu/plugin/tencent/cls/client/TencentClsLogCollectClient.java
index ae82a573e3..df7f8fb3f2 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/main/java/org/apache/shenyu/plugin/tencent/cls/client/TencentClsLogCollectClient.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/main/java/org/apache/shenyu/plugin/tencent/cls/client/TencentClsLogCollectClient.java
@@ -119,11 +119,17 @@ public class TencentClsLogCollectClient extends 
AbstractLogConsumeClient<Tencent
 
     @Override
     public void close0() {
-        if (Objects.nonNull(client)) {
-            try {
-                client.close();
-            } catch (InterruptedException | ProducerException e) {
-                LOG.error("Close producer error.");
+        try {
+            if (Objects.nonNull(client)) {
+                try {
+                    client.close();
+                } catch (InterruptedException | ProducerException e) {
+                    LOG.error("Close producer error.");
+                }
+            }
+        } finally {
+            if (Objects.nonNull(threadExecutor)) {
+                threadExecutor.shutdown();
             }
         }
     }
diff --git 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/test/java/org/apache/shenyu/plugin/tencent/cls/tencentcls/TencentClsLogCollectClientTest.java
 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/test/java/org/apache/shenyu/plugin/tencent/cls/tencentcls/TencentClsLogCollectClientTest.java
index 5f65a87481..2e41c8463d 100644
--- 
a/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/test/java/org/apache/shenyu/plugin/tencent/cls/tencentcls/TencentClsLogCollectClientTest.java
+++ 
b/shenyu-plugin/shenyu-plugin-logging/shenyu-plugin-logging-tencent-cls/src/test/java/org/apache/shenyu/plugin/tencent/cls/tencentcls/TencentClsLogCollectClientTest.java
@@ -29,6 +29,8 @@ import org.junit.jupiter.api.Test;
 import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.ThreadPoolExecutor;
+import org.springframework.test.util.ReflectionTestUtils;
 import java.util.UUID;
 
 /**
@@ -85,4 +87,23 @@ public class TencentClsLogCollectClientTest {
                 TencentLogCollectConfig.INSTANCE.getTencentClsLogConfig());
         tencentClsLogCollectClient.close();
     }
+
+    @Test
+    public void testCloseShutsDownCallbackExecutorAfterPartialInitialization() 
throws Exception {
+        ThreadPoolExecutor executor = 
org.mockito.Mockito.mock(ThreadPoolExecutor.class);
+        ReflectionTestUtils.setField(tencentClsLogCollectClient, 
"threadExecutor", executor);
+        tencentClsLogCollectClient.close0();
+        org.mockito.Mockito.verify(executor).shutdown();
+    }
+
+    @Test
+    public void testCloseShutsDownCallbackExecutorWhenProducerFails() throws 
Exception {
+        ThreadPoolExecutor executor = 
org.mockito.Mockito.mock(ThreadPoolExecutor.class);
+        ReflectionTestUtils.setField(tencentClsLogCollectClient, 
"threadExecutor", executor);
+        com.tencentcloudapi.cls.producer.AsyncProducerClient producer = 
org.mockito.Mockito.mock(com.tencentcloudapi.cls.producer.AsyncProducerClient.class);
+        ReflectionTestUtils.setField(tencentClsLogCollectClient, "client", 
producer);
+        org.mockito.Mockito.doThrow(new IllegalStateException("close 
failed")).when(producer).close();
+        Assertions.assertThrows(IllegalStateException.class, 
tencentClsLogCollectClient::close0);
+        org.mockito.Mockito.verify(executor).shutdown();
+    }
 }

Reply via email to