diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index d4f04a2fb52..e21ca62c445 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -554,6 +554,8 @@ Release 2.0.3-alpha - Unreleased HADOOP-8816. HTTP Error 413 full HEAD if using kerberos authentication. (moritzmoeller via tucu) + + HADOOP-9212. Potential deadlock in FileSystem.Cache/IPC/UGI. (tomwhite) Release 2.0.2-alpha - 2012-09-07 diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/Credentials.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/Credentials.java index a258c7f88ca..0745bed83a5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/Credentials.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/Credentials.java @@ -18,10 +18,13 @@ package org.apache.hadoop.security; +import java.io.BufferedInputStream; import java.io.DataInput; import java.io.DataInputStream; import java.io.DataOutput; import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -148,8 +151,32 @@ public class Credentials implements Writable { in.close(); return credentials; } catch(IOException ioe) { - IOUtils.cleanup(LOG, in); throw new IOException("Exception reading " + filename, ioe); + } finally { + IOUtils.cleanup(LOG, in); + } + } + + /** + * Convenience method for reading a token storage file, and loading the Tokens + * therein in the passed UGI + * @param filename + * @param conf + * @throws IOException + */ + public static Credentials readTokenStorageFile(File filename, Configuration conf) + throws IOException { + DataInputStream in = null; + Credentials credentials = new Credentials(); + try { + in = new DataInputStream(new BufferedInputStream( + new FileInputStream(filename))); + credentials.readTokenStorageStream(in); + return credentials; + } catch(IOException ioe) { + throw new IOException("Exception reading " + filename, ioe); + } finally { + IOUtils.cleanup(LOG, in); } } 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 b5cb5b518a4..b7f87e5ea89 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 @@ -20,6 +20,7 @@ package org.apache.hadoop.security; import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_KERBEROS_MIN_SECONDS_BEFORE_RELOGIN; import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_KERBEROS_MIN_SECONDS_BEFORE_RELOGIN_DEFAULT; +import java.io.File; import java.io.IOException; import java.lang.reflect.UndeclaredThrowableException; import java.security.AccessControlContext; @@ -656,10 +657,11 @@ public class UserGroupInformation { String fileLocation = System.getenv(HADOOP_TOKEN_FILE_LOCATION); if (fileLocation != null) { - // load the token storage file and put all of the tokens into the - // user. + // Load the token storage file and put all of the tokens into the + // user. Don't use the FileSystem API for reading since it has a lock + // cycle (HADOOP-9212). Credentials cred = Credentials.readTokenStorageFile( - new Path("file:///" + fileLocation), conf); + new File(fileLocation), conf); loginUser.addCredentials(cred); } loginUser.spawnAutoRenewalThreadForUserCreds();