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 d0522a06f7..a9f6cb625d 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.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 @@ static LoginParams getDefaults() { 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 void login() throws LoginException { long start = Time.monotonicNow(); try { super.login(); + isLoggedIn.set(true); metric = metrics.loginSuccess; } finally { metric.add(Time.monotonicNow() - start); @@ -1885,8 +1888,7 @@ public void login() throws LoginException { @Override public void logout() throws LoginException { synchronized(getSubjectLock()) { - if (this.getSubject() != null - && !this.getSubject().getPrivateCredentials().isEmpty()) { + if (isLoggedIn.compareAndSet(true, false)) { super.logout(); } }