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 bd2ff7b43a..0e9ea04745 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 @@ -288,8 +288,10 @@ private static String canonicalizeHost(String host) { if (fqHost == null) { try { fqHost = SecurityUtil.getByName(host).getHostName(); - // slight race condition, but won't hurt canonicalizedHostCache.putIfAbsent(host, fqHost); + // ensures that we won't return a canonicalized stale (non-cached) + // host name for a given host + fqHost = canonicalizedHostCache.get(host); } catch (UnknownHostException e) { fqHost = host; }