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

JackieTien97 pushed a commit to branch ty/fix-seed-fallback-buffer-test-race
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 9eb4567a10156552127aef84ffe29c8385125498
Author: JackieTien97 <[email protected]>
AuthorDate: Sat Nov 7 20:28:09 2026 +0800

    Fix race in SessionSeedNodeFallbackTest discovery buffer checks
    
    SessionPool schedules its first NodesSupplier refresh immediately on a
    real executor, but assertDiscoveryBufferThreshold() called run() and
    inspected the discovery connection right away. run() returns without
    waiting while another refresh holds refreshLock, so the test could see
    that background refresh half done: a null client, or the temporary
    28-byte write buffer of an in-flight openSession frame. Both failures
    were seen on Windows CI.
    
    Hold refreshLock around the refresh and the buffer assertions. The lock
    is reentrant, so run() still refreshes on the test thread, while an
    in-flight background refresh finishes first and cannot use the
    connection during the assertions.
---
 .../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