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 e1da745d7c fix(common): publish queue configuration safely (#7141)
e1da745d7c is described below

commit e1da745d7c7c324883a0be3fb3e174dc311525b6
Author: Liming Deng <[email protected]>
AuthorDate: Mon Sep 21 20:31:51 2026 +0800

    fix(common): publish queue configuration safely (#7141)
    
    Co-authored-by: aias00 <[email protected]>
---
 .../common/concurrent/MemorySafeLinkedBlockingQueue.java    |  4 ++--
 .../concurrent/MemorySafeLinkedBlockingQueueTest.java       | 13 +++++++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git 
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueue.java
 
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueue.java
index ee9e6b8bbe..6dd9a0bae2 100644
--- 
a/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueue.java
+++ 
b/shenyu-common/src/main/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueue.java
@@ -30,9 +30,9 @@ public class MemorySafeLinkedBlockingQueue<E> extends 
LinkedBlockingQueue<E> {
 
     private static final long serialVersionUID = 8032578371749960142L;
 
-    private int maxFreeMemory;
+    private volatile int maxFreeMemory;
 
-    private Rejector<E> rejector;
+    private volatile Rejector<E> rejector;
 
     public MemorySafeLinkedBlockingQueue(final int maxFreeMemory) {
         super(Integer.MAX_VALUE);
diff --git 
a/shenyu-common/src/test/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueueTest.java
 
b/shenyu-common/src/test/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueueTest.java
index 8968a972d4..60b356ea89 100644
--- 
a/shenyu-common/src/test/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueueTest.java
+++ 
b/shenyu-common/src/test/java/org/apache/shenyu/common/concurrent/MemorySafeLinkedBlockingQueueTest.java
@@ -19,9 +19,13 @@ package org.apache.shenyu.common.concurrent;
 
 import org.junit.jupiter.api.Test;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class MemorySafeLinkedBlockingQueueTest {
     @Test
@@ -44,4 +48,13 @@ public class MemorySafeLinkedBlockingQueueTest {
         assertThrows(RejectException.class, () -> queue.offer(() -> {
         }));
     }
+
+    @Test
+    public void testMutableConfigurationIsVolatile() throws 
NoSuchFieldException {
+        Field maxFreeMemory = 
MemorySafeLinkedBlockingQueue.class.getDeclaredField("maxFreeMemory");
+        Field rejector = 
MemorySafeLinkedBlockingQueue.class.getDeclaredField("rejector");
+
+        assertTrue(Modifier.isVolatile(maxFreeMemory.getModifiers()));
+        assertTrue(Modifier.isVolatile(rejector.getModifiers()));
+    }
 }

Reply via email to