pan3793 commented on code in PR #9030:
URL: https://github.com/apache/hadoop/pull/9030#discussion_r4749999931


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java:
##########
@@ -619,6 +620,13 @@ public static void connect(Socket socket,
       throw new ConnectTimeoutException(ste.getMessage());
     }  catch (UnresolvedAddressException uae) {
       throw new UnknownHostException(endpoint.toString());
+    } catch (UnsupportedAddressTypeException uate) {
+      // Unchecked and message-less, so name the endpoint the socket cannot 
use.
+      SocketException se = new SocketException("Cannot connect to " + endpoint
+          + ": address type not supported by this socket. A common cause is an"
+          + " IPv6 address used from a JVM with 
java.net.preferIPv4Stack=true.");
+      se.initCause(uate);
+      throw se;

Review Comment:
   Non-blocking: the IPv6/`preferIPv4Stack` hint is appended unconditionally, 
but the exception also fires for endpoints that are not an `InetSocketAddress` 
(the case the new test triggers), where the hint is misleading. Could you guard 
the hint with a check that the endpoint is an IPv6 `InetSocketAddress` before 
appending it? For example:
   
   ```java
   } catch (UnsupportedAddressTypeException uate) {
     String msg = "Cannot connect to " + endpoint
         + ": address type not supported by this socket";
     if (endpoint instanceof InetSocketAddress
         && ((InetSocketAddress) endpoint).getAddress() instanceof 
Inet6Address) {
       msg += "; IPv6 is not available to this JVM,"
           + " check java.net.preferIPv4Stack and OS IPv6 support";
     }
     SocketException se = new SocketException(msg);
     se.initCause(uate);
     throw se;
   }
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to