This is an automated email from the ASF dual-hosted git repository.

liuhongyu 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 b97c7db820 [#6262] Fix OrderlyExecutor resource leak in 
shenyu-disruptor (#6269)
b97c7db820 is described below

commit b97c7db820e68cd052a9d9938eef33551d2a4ab6
Author: Aira Jena <[email protected]>
AuthorDate: Mon Jan 5 12:13:57 2026 +0530

    [#6262] Fix OrderlyExecutor resource leak in shenyu-disruptor (#6269)
---
 .../apache/shenyu/disruptor/DisruptorProviderManage.java   |  2 +-
 .../shenyu/disruptor/provider/DisruptorProvider.java       | 10 +++++++++-
 .../shenyu/disruptor/provider/DisruptorProviderTest.java   | 14 ++++++++++----
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git 
a/shenyu-disruptor/src/main/java/org/apache/shenyu/disruptor/DisruptorProviderManage.java
 
b/shenyu-disruptor/src/main/java/org/apache/shenyu/disruptor/DisruptorProviderManage.java
index 3a37bc4de0..5f13b3f66b 100644
--- 
a/shenyu-disruptor/src/main/java/org/apache/shenyu/disruptor/DisruptorProviderManage.java
+++ 
b/shenyu-disruptor/src/main/java/org/apache/shenyu/disruptor/DisruptorProviderManage.java
@@ -130,7 +130,7 @@ public class DisruptorProviderManage<T> {
         disruptor.setDefaultExceptionHandler(new IgnoreExceptionHandler());
         disruptor.start();
         RingBuffer<DataEvent<T>> ringBuffer = disruptor.getRingBuffer();
-        provider = new DisruptorProvider<>(ringBuffer, disruptor, isOrderly);
+        provider = new DisruptorProvider<>(ringBuffer, disruptor, isOrderly, 
executor);
     }
     
     /**
diff --git 
a/shenyu-disruptor/src/main/java/org/apache/shenyu/disruptor/provider/DisruptorProvider.java
 
b/shenyu-disruptor/src/main/java/org/apache/shenyu/disruptor/provider/DisruptorProvider.java
index d3d16c3a27..7effd35c53 100644
--- 
a/shenyu-disruptor/src/main/java/org/apache/shenyu/disruptor/provider/DisruptorProvider.java
+++ 
b/shenyu-disruptor/src/main/java/org/apache/shenyu/disruptor/provider/DisruptorProvider.java
@@ -27,6 +27,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.Objects;
+import java.util.concurrent.ExecutorService;
 
 /**
  * DisruptorProvider.
@@ -42,6 +43,8 @@ public class DisruptorProvider<T> {
     
     private final boolean isOrderly;
     
+    private final ExecutorService executor;
+    
     private final EventTranslatorOneArg<DataEvent<T>, T> translatorOneArg = 
(event, sequence, t) -> event.setData(t);
     
     private final EventTranslatorTwoArg<DataEvent<T>, T, String> orderlyArg = 
(event, sequence, t, orderly) -> {
@@ -62,11 +65,13 @@ public class DisruptorProvider<T> {
      * @param ringBuffer the ring buffer
      * @param disruptor  the disruptor
      * @param isOrderly  the orderly Whether to execute sequentially.
+     * @param executor   the executor service to be managed
      */
-    public DisruptorProvider(final RingBuffer<DataEvent<T>> ringBuffer, final 
Disruptor<DataEvent<T>> disruptor, final boolean isOrderly) {
+    public DisruptorProvider(final RingBuffer<DataEvent<T>> ringBuffer, final 
Disruptor<DataEvent<T>> disruptor, final boolean isOrderly, final 
ExecutorService executor) {
         this.ringBuffer = ringBuffer;
         this.disruptor = disruptor;
         this.isOrderly = isOrderly;
+        this.executor = executor;
     }
 
     /**
@@ -110,5 +115,8 @@ public class DisruptorProvider<T> {
         if (Objects.nonNull(disruptor)) {
             disruptor.shutdown();
         }
+        if (Objects.nonNull(executor)) {
+            executor.shutdown();
+        }
     }
 }
diff --git 
a/shenyu-disruptor/src/test/java/org/apache/shenyu/disruptor/provider/DisruptorProviderTest.java
 
b/shenyu-disruptor/src/test/java/org/apache/shenyu/disruptor/provider/DisruptorProviderTest.java
index 6333165f73..56aa996da0 100644
--- 
a/shenyu-disruptor/src/test/java/org/apache/shenyu/disruptor/provider/DisruptorProviderTest.java
+++ 
b/shenyu-disruptor/src/test/java/org/apache/shenyu/disruptor/provider/DisruptorProviderTest.java
@@ -31,12 +31,16 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoInteractions;
 
+import java.util.concurrent.ExecutorService;
+
 class DisruptorProviderTest {
 
     private RingBuffer<DataEvent<String>> mockRingBuffer;
 
     private Disruptor<DataEvent<String>> mockDisruptor;
 
+    private ExecutorService mockExecutor;
+
     private DisruptorProvider<String> disruptorProvider;
 
     @BeforeEach
@@ -44,7 +48,8 @@ class DisruptorProviderTest {
 
         mockRingBuffer = mock(RingBuffer.class);
         mockDisruptor = mock(Disruptor.class);
-        disruptorProvider = new DisruptorProvider<>(mockRingBuffer, 
mockDisruptor, false);
+        mockExecutor = mock(ExecutorService.class);
+        disruptorProvider = new DisruptorProvider<>(mockRingBuffer, 
mockDisruptor, false, mockExecutor);
     }
 
     @Test
@@ -60,7 +65,7 @@ class DisruptorProviderTest {
     @Test
     void testOnDataThrowsExceptionForOrderlyProvider() {
 
-        disruptorProvider = new DisruptorProvider<>(mockRingBuffer, 
mockDisruptor, true);
+        disruptorProvider = new DisruptorProvider<>(mockRingBuffer, 
mockDisruptor, true, mockExecutor);
 
         IllegalArgumentException exception = 
assertThrows(IllegalArgumentException.class, () -> 
disruptorProvider.onData("testData"));
         assertEquals("The current provider is  of orderly type. Please use 
onOrderlyData() method.", exception.getMessage());
@@ -69,7 +74,7 @@ class DisruptorProviderTest {
     @Test
     void testOnOrderlyData() {
 
-        disruptorProvider = new DisruptorProvider<>(mockRingBuffer, 
mockDisruptor, true);
+        disruptorProvider = new DisruptorProvider<>(mockRingBuffer, 
mockDisruptor, true, mockExecutor);
         String testData = "testData";
         String[] hashArray = {"hash1", "hash2"};
 
@@ -94,12 +99,13 @@ class DisruptorProviderTest {
         disruptorProvider.shutdown();
 
         verify(mockDisruptor).shutdown();
+        verify(mockExecutor).shutdown();
     }
 
     @Test
     void testShutdownWithNullDisruptor() {
 
-        disruptorProvider = new DisruptorProvider<>(mockRingBuffer, null, 
false);
+        disruptorProvider = new DisruptorProvider<>(mockRingBuffer, null, 
false, null);
 
         disruptorProvider.shutdown();
 

Reply via email to