From bbc8dfcb8b5acd92aa3a2d945a1d51403cdde874 Mon Sep 17 00:00:00 2001 From: Daryn Sharp Date: Wed, 25 Apr 2018 17:05:42 +0900 Subject: [PATCH] HADOOP-15402. Prevent double logout of UGI's LoginContext Signed-off-by: Akira Ajisaka --- .../org/apache/hadoop/security/UserGroupInformation.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java index d0522a06f77..a9f6cb625d5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/UserGroupInformation.java @@ -47,6 +47,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import javax.security.auth.DestroyFailedException; @@ -1843,6 +1844,7 @@ public class UserGroupInformation { private static class HadoopLoginContext extends LoginContext { private final String appName; private final HadoopConfiguration conf; + private AtomicBoolean isLoggedIn = new AtomicBoolean(); HadoopLoginContext(String appName, Subject subject, HadoopConfiguration conf) throws LoginException { @@ -1875,6 +1877,7 @@ public class UserGroupInformation { long start = Time.monotonicNow(); try { super.login(); + isLoggedIn.set(true); metric = metrics.loginSuccess; } finally { metric.add(Time.monotonicNow() - start); @@ -1885,8 +1888,7 @@ public class UserGroupInformation { @Override public void logout() throws LoginException { synchronized(getSubjectLock()) { - if (this.getSubject() != null - && !this.getSubject().getPrivateCredentials().isEmpty()) { + if (isLoggedIn.compareAndSet(true, false)) { super.logout(); } }