From 36e29abf4168646b4e3866061c00b5cbea6fcead Mon Sep 17 00:00:00 2001 From: jiangyuan <469391363@qq.com> Date: Tue, 15 Oct 2024 03:33:06 +0800 Subject: [PATCH] fix XdsTestServer/TestServiceServer listenAddresses conflict (#11612) --- .../grpc/testing/integration/TestServiceServer.java | 12 ++++++++---- .../io/grpc/testing/integration/XdsTestServer.java | 13 ++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java index 01cccf98044..fc4cdf9178f 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/TestServiceServer.java @@ -180,18 +180,22 @@ void start() throws Exception { break; case IPV4: SocketAddress v4Address = Util.getV4Address(port); + InetSocketAddress localV4Address = new InetSocketAddress("127.0.0.1", port); serverBuilder = - NettyServerBuilder.forAddress(new InetSocketAddress("127.0.0.1", port), serverCreds); - if (v4Address == null) { + NettyServerBuilder.forAddress(localV4Address, serverCreds); + if (v4Address != null && !v4Address.equals(localV4Address)) { ((NettyServerBuilder) serverBuilder).addListenAddress(v4Address); } break; case IPV6: List v6Addresses = Util.getV6Addresses(port); + InetSocketAddress localV6Address = new InetSocketAddress("::1", port); serverBuilder = - NettyServerBuilder.forAddress(new InetSocketAddress("::1", port), serverCreds); + NettyServerBuilder.forAddress(localV6Address, serverCreds); for (SocketAddress address : v6Addresses) { - ((NettyServerBuilder)serverBuilder).addListenAddress(address); + if (!address.equals(localV6Address)) { + ((NettyServerBuilder) serverBuilder).addListenAddress(address); + } } break; default: diff --git a/interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java b/interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java index 8c61f2eb2ad..2f1625d1581 100644 --- a/interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java +++ b/interop-testing/src/main/java/io/grpc/testing/integration/XdsTestServer.java @@ -242,18 +242,21 @@ void start() throws Exception { break; case IPV4: SocketAddress v4Address = Util.getV4Address(port); + InetSocketAddress localV4Address = new InetSocketAddress("127.0.0.1", port); serverBuilder = NettyServerBuilder.forAddress( - new InetSocketAddress("127.0.0.1", port), insecureServerCreds); - if (v4Address != null) { + localV4Address, insecureServerCreds); + if (v4Address != null && !v4Address.equals(localV4Address) ) { ((NettyServerBuilder) serverBuilder).addListenAddress(v4Address); } break; case IPV6: List v6Addresses = Util.getV6Addresses(port); - serverBuilder = NettyServerBuilder.forAddress( - new InetSocketAddress("::1", port), insecureServerCreds); + InetSocketAddress localV6Address = new InetSocketAddress("::1", port); + serverBuilder = NettyServerBuilder.forAddress(localV6Address, insecureServerCreds); for (SocketAddress address : v6Addresses) { - ((NettyServerBuilder)serverBuilder).addListenAddress(address); + if (!address.equals(localV6Address)) { + ((NettyServerBuilder) serverBuilder).addListenAddress(address); + } } break; default: