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

JackieTien97 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new a48b879779e Fix race in SessionSeedNodeFallbackTest discovery buffer 
checks (#19173)
a48b879779e is described below

commit a48b879779e1d138af941ad203e46cc867fdff6f
Author: Jackie Tien <[email protected]>
AuthorDate: Sun Nov 8 14:12:21 2026 +0800

    Fix race in SessionSeedNodeFallbackTest discovery buffer checks (#19173)
---
 .../iotdb/session/SessionSeedNodeFallbackTest.java | 24 ++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git 
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionSeedNodeFallbackTest.java
 
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionSeedNodeFallbackTest.java
index ad5767a07c6..bbcdda2abed 100644
--- 
a/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionSeedNodeFallbackTest.java
+++ 
b/iotdb-client/session/src/test/java/org/apache/iotdb/session/SessionSeedNodeFallbackTest.java
@@ -72,6 +72,7 @@ import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantLock;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
@@ -574,13 +575,24 @@ public class SessionSeedNodeFallbackTest {
     }
   }
 
-  private void assertDiscoveryBufferThreshold(SessionPool pool, int threshold) 
{
+  private void assertDiscoveryBufferThreshold(SessionPool pool, int threshold)
+      throws InterruptedException {
     NodesSupplier current = Whitebox.getInternalState(pool, "availableNodes");
-    current.run();
-    ThriftConnection connection = Whitebox.getInternalState(current, "client");
-    AutoScalingBufferWriteTransport output = 
assertTransportBufferThreshold(connection, threshold);
-    if (threshold == 0) {
-      assertEquals(32, output.getBuffer().length);
+    // The pool starts its first discovery refresh immediately, and run() 
returns at once while
+    // another refresh holds refreshLock. Holding the reentrant lock waits for 
that refresh and
+    // keeps the discovery connection idle while run() refreshes it and its 
buffers are checked.
+    ReentrantLock refreshLock = Whitebox.getInternalState(current, 
"refreshLock");
+    assertTrue(refreshLock.tryLock(10, TimeUnit.SECONDS));
+    try {
+      current.run();
+      ThriftConnection connection = Whitebox.getInternalState(current, 
"client");
+      AutoScalingBufferWriteTransport output =
+          assertTransportBufferThreshold(connection, threshold);
+      if (threshold == 0) {
+        assertEquals(32, output.getBuffer().length);
+      }
+    } finally {
+      refreshLock.unlock();
     }
   }
 

Reply via email to