HADOOP-17052. NetUtils.connect() throws unchecked exception (UnresolvedAddressException) causing clients to abort (#2036)
Contributed by Dhiraj Hegde. Signed-off-by: Mingliang Liu <liuml07@apache.org>
This commit is contained in:
parent
aa19cb20ea
commit
2c40f20deb
@ -37,6 +37,7 @@
|
|||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.net.ConnectException;
|
import java.net.ConnectException;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
|
import java.nio.channels.UnresolvedAddressException;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -532,6 +533,8 @@ public static void connect(Socket socket,
|
|||||||
}
|
}
|
||||||
} catch (SocketTimeoutException ste) {
|
} catch (SocketTimeoutException ste) {
|
||||||
throw new ConnectTimeoutException(ste.getMessage());
|
throw new ConnectTimeoutException(ste.getMessage());
|
||||||
|
} catch (UnresolvedAddressException uae) {
|
||||||
|
throw new UnknownHostException(uae.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// There is a very rare case allowed by the TCP specification, such that
|
// There is a very rare case allowed by the TCP specification, such that
|
||||||
|
@ -96,6 +96,24 @@ public void testAvoidLoopbackTcpSockets() throws Throwable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testInvalidAddress() throws Throwable {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
|
||||||
|
Socket socket = NetUtils.getDefaultSocketFactory(conf)
|
||||||
|
.createSocket();
|
||||||
|
socket.bind(new InetSocketAddress("127.0.0.1", 0));
|
||||||
|
try {
|
||||||
|
NetUtils.connect(socket,
|
||||||
|
new InetSocketAddress("invalid-test-host",
|
||||||
|
0), 20000);
|
||||||
|
socket.close();
|
||||||
|
fail("Should not have connected");
|
||||||
|
} catch (UnknownHostException uhe) {
|
||||||
|
LOG.info("Got exception: ", uhe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSocketReadTimeoutWithChannel() throws Exception {
|
public void testSocketReadTimeoutWithChannel() throws Exception {
|
||||||
doSocketReadTimeoutTest(true);
|
doSocketReadTimeoutTest(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user