Skip to content

Commit

Permalink
[ISSUE #7822] fix NettyRemotingClient can't connect to IPv6 address. (#…
Browse files Browse the repository at this point in the history
…7823)

* #7822 fix NettyRemotingClient can't connect to IPv6 address.

* #7822 fix NettyRemotingClient can't connect to IPv6 address.
  • Loading branch information
kingkh1995 authored Feb 8, 2024
1 parent 5e61354 commit 3acc262
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,10 @@ public void initChannel(SocketChannel ch) {
return bootstrap;
}

// Do not use RemotingUtil, it will directly resolve the domain
// Do not use RemotingHelper.string2SocketAddress(), it will directly resolve the domain
private String[] getHostAndPort(String address) {
return address.split(":");
int split = address.lastIndexOf(":");
return split < 0 ? new String[]{address} : new String[]{address.substring(0, split), address.substring(split + 1)};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
*/
package org.apache.rocketmq.remoting.netty;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.local.LocalChannel;

import java.lang.reflect.Field;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -50,6 +53,7 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

Expand Down Expand Up @@ -290,4 +294,16 @@ public void testInvokeImplFail() {
verify(rpcHookMock).doBeforeRequest(anyString(), eq(request));
verify(rpcHookMock, never()).doAfterResponse(anyString(), eq(request), any());
}

@Test
public void testIsAddressReachableFail() throws NoSuchFieldException, IllegalAccessException {
Bootstrap bootstrap = spy(Bootstrap.class);
Field field = NettyRemotingClient.class.getDeclaredField("bootstrap");
field.setAccessible(true);
field.set(remotingClient, bootstrap);
assertThat(remotingClient.isAddressReachable("0.0.0.0:8080")).isFalse();
verify(bootstrap).connect(eq("0.0.0.0"), eq(8080));
assertThat(remotingClient.isAddressReachable("[fe80::]:8080")).isFalse();
verify(bootstrap).connect(eq("[fe80::]"), eq(8080));
}
}

0 comments on commit 3acc262

Please sign in to comment.