From 2b94e51a8f17548e5ef6af8e1e934a94031bb1dc Mon Sep 17 00:00:00 2001 From: Praveen Krishna Date: Thu, 7 Mar 2019 11:06:34 +0000 Subject: [PATCH] HADOOP-16114. NetUtils#canonicalizeHost gives different value for same host. Author: Praveen Krishna --- .../src/main/java/org/apache/hadoop/net/NetUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 bd2ff7b43aa..0e9ea047453 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 @@ public class NetUtils { 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; }