Browse Source

YARN-2905. AggregatedLogsBlock page can infinitely loop if the aggregated log file is corrupted. Contributed by Varun Saxena
(cherry picked from commit 0f9528b99addbb0fd9a19d84db22a8c8e934b05f)

(cherry picked from commit 38ea1419f60d2b8176dba4931748f1f0e52ca84e)
(cherry picked from commit 3877166754956bf66a8b1c81440dba2d279a1e03)

Jason Lowe 10 years ago
parent
commit
2f0a34b5ba

+ 3 - 0
hadoop-yarn-project/CHANGES.txt

@@ -27,6 +27,9 @@ Release 2.6.1 - UNRELEASED
     YARN-2906. CapacitySchedulerPage shows HTML tags for a queue's Active Users.
     (Jason Lowe via jianhe)
 
+    YARN-2905. AggregatedLogsBlock page can infinitely loop if the aggregated
+    log file is corrupted (Varun Saxena via jlowe)
+
 Release 2.6.0 - 2014-11-18
 
   INCOMPATIBLE CHANGES

+ 4 - 0
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogFormat.java

@@ -801,6 +801,10 @@ public class AggregatedLogFormat {
       return currentLogData.skip(n);
     }
 
+    public int read() throws IOException {
+      return currentLogData.read();
+    }
+
     public int read(byte[] buf, int off, int len) throws IOException {
       return currentLogData.read(buf, off, len);
     }

+ 8 - 2
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/webapp/log/AggregatedLogsBlock.java

@@ -231,8 +231,14 @@ public class AggregatedLogsBlock extends HtmlBlock {
         long totalSkipped = 0;
         while (totalSkipped < start) {
           long ret = logReader.skip(start - totalSkipped);
-          if (ret < 0) {
-            throw new IOException( "Premature EOF from container log");
+          if (ret == 0) {
+            //Read one byte
+            int nextByte = logReader.read();
+            // Check if we have reached EOF
+            if (nextByte == -1) {
+              throw new IOException( "Premature EOF from container log");
+            }
+            ret = 1;
           }
           totalSkipped += ret;
         }