HADOOP-16114. NetUtils#canonicalizeHost gives different value for same host.

Author:    Praveen Krishna <praveenkrishna@tutanota.com>
This commit is contained in:
Praveen Krishna 2019-03-07 11:06:34 +00:00 committed by Steve Loughran
parent 0eba4079bc
commit 2b94e51a8f
No known key found for this signature in database
GPG Key ID: D22CF846DBB162A0

View File

@ -288,8 +288,10 @@ private static String canonicalizeHost(String host) {
if (fqHost == null) { if (fqHost == null) {
try { try {
fqHost = SecurityUtil.getByName(host).getHostName(); fqHost = SecurityUtil.getByName(host).getHostName();
// slight race condition, but won't hurt
canonicalizedHostCache.putIfAbsent(host, fqHost); 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) { } catch (UnknownHostException e) {
fqHost = host; fqHost = host;
} }