Skip to content

Commit

Permalink
fix XdsTestServer/TestServiceServer listenAddresses conflict (grpc#11612
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JoeCqupt authored Oct 14, 2024
1 parent ca43d78 commit 36e29ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketAddress> 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketAddress> 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:
Expand Down

0 comments on commit 36e29ab

Please sign in to comment.