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:
cxzl25 2023-04-25 06:22:49 +08:00 committed by GitHub
parent c9e0af9961
commit 2f66f0b83a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 3 deletions

View File

@ -590,9 +590,8 @@ private synchronized boolean updateAddress() throws IOException {
InetSocketAddress currentAddr = NetUtils.createSocketAddrForHost(
server.getHostName(), server.getPort());
if (!server.equals(currentAddr)) {
LOG.warn("Address change detected. Old: " + server.toString() +
" New: " + currentAddr.toString());
if (!currentAddr.isUnresolved() && !server.equals(currentAddr)) {
LOG.warn("Address change detected. Old: {} New: {}", server, currentAddr);
server = currentAddr;
// Update the remote address so that reconnections are with the updated address.
// This avoids thrashing.

View File

@ -1728,6 +1728,47 @@ public void testProxyUserBinding() throws Exception {
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 {
Socket s;
// don't attempt bind with no service host.