Browse Source

HDFS-4017. Unclosed FileInputStream in GetJournalEditServlet. Contributed by Chao Shi.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/HDFS-3077@1395727 13f79535-47bb-0310-9956-ffa450edef68
Todd Lipcon 12 years ago
parent
commit
70fc5cf01c

+ 2 - 0
hadoop-hdfs-project/hadoop-hdfs/CHANGES.HDFS-3077.txt

@@ -84,3 +84,5 @@ HDFS-3955. QJM: Make acceptRecovery() atomic. (todd)
 HDFS-3956. QJM: purge temporary files when no longer within retention period (todd)
 HDFS-3956. QJM: purge temporary files when no longer within retention period (todd)
 
 
 HDFS-4004. TestJournalNode#testJournal fails because of test case execution order (Chao Shi via todd)
 HDFS-4004. TestJournalNode#testJournal fails because of test case execution order (Chao Shi via todd)
+
+HDFS-4017. Unclosed FileInputStream in GetJournalEditServlet (Chao Shi via todd)

+ 5 - 2
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/qjournal/server/GetJournalEditServlet.java

@@ -46,6 +46,7 @@ import org.apache.hadoop.hdfs.server.namenode.SecondaryNameNode;
 import org.apache.hadoop.hdfs.server.namenode.TransferFsImage;
 import org.apache.hadoop.hdfs.server.namenode.TransferFsImage;
 import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
 import org.apache.hadoop.hdfs.server.protocol.NamespaceInfo;
 import org.apache.hadoop.hdfs.util.DataTransferThrottler;
 import org.apache.hadoop.hdfs.util.DataTransferThrottler;
+import org.apache.hadoop.io.IOUtils;
 import org.apache.hadoop.security.SecurityUtil;
 import org.apache.hadoop.security.SecurityUtil;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.security.UserGroupInformation;
 import org.apache.hadoop.util.ServletUtil;
 import org.apache.hadoop.util.ServletUtil;
@@ -157,6 +158,7 @@ public class GetJournalEditServlet extends HttpServlet {
   @Override
   @Override
   public void doGet(final HttpServletRequest request,
   public void doGet(final HttpServletRequest request,
       final HttpServletResponse response) throws ServletException, IOException {
       final HttpServletResponse response) throws ServletException, IOException {
+    FileInputStream editFileIn = null;
     try {
     try {
       final ServletContext context = getServletContext();
       final ServletContext context = getServletContext();
       final Configuration conf = (Configuration) getServletContext()
       final Configuration conf = (Configuration) getServletContext()
@@ -181,8 +183,7 @@ public class GetJournalEditServlet extends HttpServlet {
 
 
       FileJournalManager fjm = storage.getJournalManager();
       FileJournalManager fjm = storage.getJournalManager();
       File editFile;
       File editFile;
-      FileInputStream editFileIn;
-      
+
       synchronized (fjm) {
       synchronized (fjm) {
         // Synchronize on the FJM so that the file doesn't get finalized
         // Synchronize on the FJM so that the file doesn't get finalized
         // out from underneath us while we're in the process of opening
         // out from underneath us while we're in the process of opening
@@ -209,6 +210,8 @@ public class GetJournalEditServlet extends HttpServlet {
       String errMsg = "getedit failed. " + StringUtils.stringifyException(t);
       String errMsg = "getedit failed. " + StringUtils.stringifyException(t);
       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errMsg);
       response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errMsg);
       throw new IOException(errMsg);
       throw new IOException(errMsg);
+    } finally {
+      IOUtils.closeStream(editFileIn);
     }
     }
   }
   }