HADOOP-18694. Client.Connection#updateAddress needs to ensure that address is resolved before updating (#5542). Contributed by dzcxzl.
Reviewed-by: Steve Vaughan <email@stevevaughan.me> Reviewed-by: He Xiaoqiao <hexiaoqiao@apache.org> Signed-off-by: Ayush Saxena <ayushsaxena@apache.org
This commit is contained in:
parent
c9e0af9961
commit
2f66f0b83a
@ -590,9 +590,8 @@ private synchronized boolean updateAddress() throws IOException {
|
|||||||
InetSocketAddress currentAddr = NetUtils.createSocketAddrForHost(
|
InetSocketAddress currentAddr = NetUtils.createSocketAddrForHost(
|
||||||
server.getHostName(), server.getPort());
|
server.getHostName(), server.getPort());
|
||||||
|
|
||||||
if (!server.equals(currentAddr)) {
|
if (!currentAddr.isUnresolved() && !server.equals(currentAddr)) {
|
||||||
LOG.warn("Address change detected. Old: " + server.toString() +
|
LOG.warn("Address change detected. Old: {} New: {}", server, currentAddr);
|
||||||
" New: " + currentAddr.toString());
|
|
||||||
server = currentAddr;
|
server = currentAddr;
|
||||||
// Update the remote address so that reconnections are with the updated address.
|
// Update the remote address so that reconnections are with the updated address.
|
||||||
// This avoids thrashing.
|
// This avoids thrashing.
|
||||||
|
@ -1728,6 +1728,47 @@ public void testProxyUserBinding() throws Exception {
|
|||||||
checkUserBinding(true);
|
checkUserBinding(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(timeout=60000)
|
||||||
|
public void testUpdateAddressEnsureResolved() throws Exception {
|
||||||
|
// start server
|
||||||
|
Server server = new TestServer(1, false);
|
||||||
|
server.start();
|
||||||
|
|
||||||
|
SocketFactory mockFactory = Mockito.mock(SocketFactory.class);
|
||||||
|
doThrow(new ConnectTimeoutException("fake")).when(mockFactory)
|
||||||
|
.createSocket();
|
||||||
|
Client client = new Client(LongWritable.class, conf, mockFactory);
|
||||||
|
InetSocketAddress address =
|
||||||
|
new InetSocketAddress("localhost", NetUtils.getFreeSocketPort());
|
||||||
|
ConnectionId remoteId = getConnectionId(address, 100, conf);
|
||||||
|
try {
|
||||||
|
LambdaTestUtils.intercept(IOException.class, (Callable<Void>) () -> {
|
||||||
|
client.call(RpcKind.RPC_BUILTIN, new LongWritable(RANDOM.nextLong()),
|
||||||
|
remoteId, RPC.RPC_SERVICE_CLASS_DEFAULT, null);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
assertFalse(address.isUnresolved());
|
||||||
|
assertFalse(remoteId.getAddress().isUnresolved());
|
||||||
|
assertEquals(System.identityHashCode(remoteId.getAddress()),
|
||||||
|
System.identityHashCode(address));
|
||||||
|
|
||||||
|
NetUtils.addStaticResolution("localhost", "host.invalid");
|
||||||
|
LambdaTestUtils.intercept(IOException.class, (Callable<Void>) () -> {
|
||||||
|
client.call(RpcKind.RPC_BUILTIN, new LongWritable(RANDOM.nextLong()),
|
||||||
|
remoteId, RPC.RPC_SERVICE_CLASS_DEFAULT, null);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
assertFalse(remoteId.getAddress().isUnresolved());
|
||||||
|
assertEquals(System.identityHashCode(remoteId.getAddress()),
|
||||||
|
System.identityHashCode(address));
|
||||||
|
} finally {
|
||||||
|
client.stop();
|
||||||
|
server.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkUserBinding(boolean asProxy) throws Exception {
|
private void checkUserBinding(boolean asProxy) throws Exception {
|
||||||
Socket s;
|
Socket s;
|
||||||
// don't attempt bind with no service host.
|
// don't attempt bind with no service host.
|
||||||
|
Loading…
Reference in New Issue
Block a user