From 28ecd5244939ee42cfd55decbd2185fb3187a611 Mon Sep 17 00:00:00 2001 From: Tsz-Wo Nicholas Sze Date: Wed, 9 Sep 2026 10:55:45 -0700 Subject: [PATCH] RATIS-2675. Fix TestTlsConfWithNetty may fail with "address already in use" TestTlsConfWithNetty.randomPort() picked a random integer in [50000, 60000) without verifying availability, so a busy port in that range made ServerBootstrap.bind() throw BindException. Route through the existing NetUtils.getFreePort(), which probes ports with a ServerSocket before returning them, the same helper MiniRaftCluster and other tests already use. Co-Authored-By: Claude Code --- .../java/org/apache/ratis/netty/TestTlsConfWithNetty.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ratis-test/src/test/java/org/apache/ratis/netty/TestTlsConfWithNetty.java b/ratis-test/src/test/java/org/apache/ratis/netty/TestTlsConfWithNetty.java index ca913d7bce..50e4435a19 100644 --- a/ratis-test/src/test/java/org/apache/ratis/netty/TestTlsConfWithNetty.java +++ b/ratis-test/src/test/java/org/apache/ratis/netty/TestTlsConfWithNetty.java @@ -40,6 +40,7 @@ import org.apache.ratis.thirdparty.io.netty.handler.ssl.SslContext; import org.apache.ratis.thirdparty.io.netty.handler.ssl.SslProvider; import org.apache.ratis.util.JavaUtils; +import org.apache.ratis.util.NetUtils; import org.apache.ratis.util.NettyUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -55,7 +56,6 @@ import java.util.List; import java.util.Queue; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; @@ -80,7 +80,7 @@ static ByteBuf unpooledBuffer(String s) { } static int randomPort() { - final int port = 50000 + ThreadLocalRandom.current().nextInt(10000); + final int port = NetUtils.getFreePort(); LOG.info("randomPort: {}", port); return port; }