Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.net.UnknownHostException;
import java.net.ConnectException;
import java.nio.channels.SocketChannel;
import java.nio.channels.UnresolvedAddressException;
import java.util.Map.Entry;
import java.util.regex.Pattern;
import java.util.*;
Expand Down Expand Up @@ -534,6 +535,8 @@ public static void connect(Socket socket,
}
} catch (SocketTimeoutException ste) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,25 @@ public void testAvoidLoopbackTcpSockets() throws Throwable {
assertInException(se, "Invalid argument");
}
}


@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
public void testSocketReadTimeoutWithChannel() throws Exception {
doSocketReadTimeoutTest(true);
Expand Down