From 4fe42683360e562dec86b904464b7fd038c7aae6 Mon Sep 17 00:00:00 2001 From: Jason Darrell Lowe Date: Tue, 18 Feb 2014 15:23:29 +0000 Subject: [PATCH] HADOOP-10346. Deadlock while logging tokens. Contributed by Jason Lowe git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1569382 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-common-project/hadoop-common/CHANGES.txt | 2 ++ .../org/apache/hadoop/security/token/Token.java | 17 ++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 442d58349d..10bbc2f30e 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -357,6 +357,8 @@ Release 2.4.0 - UNRELEASED HADOOP-10249. LdapGroupsMapping should trim ldap password read from file. (Dilli Armugam via suresh) + HADOOP-10346. Deadlock while logging tokens (jlowe) + Release 2.3.1 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/Token.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/Token.java index 14d81910b5..3944ad1282 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/Token.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/token/Token.java @@ -105,18 +105,21 @@ public byte[] getIdentifier() { return identifier; } - private static synchronized Class + private static Class getClassForIdentifier(Text kind) { - if (tokenKindMap == null) { - tokenKindMap = Maps.newHashMap(); - for (TokenIdentifier id : ServiceLoader.load(TokenIdentifier.class)) { - tokenKindMap.put(id.getKind(), id.getClass()); + Class cls = null; + synchronized (Token.class) { + if (tokenKindMap == null) { + tokenKindMap = Maps.newHashMap(); + for (TokenIdentifier id : ServiceLoader.load(TokenIdentifier.class)) { + tokenKindMap.put(id.getKind(), id.getClass()); + } } + cls = tokenKindMap.get(kind); } - Class cls = tokenKindMap.get(kind); if (cls == null) { LOG.warn("Cannot find class for token kind " + kind); - return null; + return null; } return cls; }