From 0c8a2c26098c8a3f77e4770391b4fc3e1c0245a5 Mon Sep 17 00:00:00 2001 From: Varun Saxena Date: Wed, 25 Oct 2017 03:06:12 +0530 Subject: [PATCH] HADOOP-9657. NetUtils.wrapException to have special handling for 0.0.0.0 addresses and :0 ports. Contributed by Varun Saxena. (cherry picked from commit 67e7673750e731f5ecfa84e82b84b7fc7ee0b233) --- .../java/org/apache/hadoop/net/NetUtils.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java index 85773364c43..4697320a801 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetUtils.java @@ -742,18 +742,27 @@ public class NetUtils { + ";" + see("BindException")); } else if (exception instanceof ConnectException) { - // connection refused; include the host:port in the error - return wrapWithMessage(exception, - "Call From " - + localHost - + " to " - + destHost - + ":" - + destPort - + " failed on connection exception: " - + exception - + ";" - + see("ConnectionRefused")); + // Check if client was trying to connect to an unspecified IPv4 address + // (0.0.0.0) or IPv6 address(0:0:0:0:0:0:0:0 or ::) + if ((destHost != null && (destHost.equals("0.0.0.0") || + destHost.equals("0:0:0:0:0:0:0:0") || destHost.equals("::"))) + || destPort == 0) { + return wrapWithMessage(exception, "Your endpoint configuration" + + " is wrong;" + see("UnsetHostnameOrPort")); + } else { + // connection refused; include the host:port in the error + return wrapWithMessage(exception, + "Call From " + + localHost + + " to " + + destHost + + ":" + + destPort + + " failed on connection exception: " + + exception + + ";" + + see("ConnectionRefused")); + } } else if (exception instanceof UnknownHostException) { return wrapWithMessage(exception, "Invalid host name: "