Browse Source

svn merge -c 1302754 FIXES: MAPREDUCE-3992. Reduce fetcher doesn't verify HTTP status code of response. Contributed by Todd Lipcon.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.23@1359708 13f79535-47bb-0310-9956-ffa450edef68
Robert Joseph Evans 13 years ago
parent
commit
bb9d42544c

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

@@ -304,6 +304,9 @@ Release 0.23.3 - UNRELEASED
     MAPREDUCE-4300. OOM in AM can turn it into a zombie. (Robert Evans via
     MAPREDUCE-4300. OOM in AM can turn it into a zombie. (Robert Evans via
     tgraves)
     tgraves)
 
 
+    MAPREDUCE-3992. Reduce fetcher doesn't verify HTTP status code of response
+    (todd)
+
 Release 0.23.2 - UNRELEASED
 Release 0.23.2 - UNRELEASED
 
 
   INCOMPATIBLE CHANGES
   INCOMPATIBLE CHANGES

+ 10 - 1
hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-core/src/main/java/org/apache/hadoop/mapreduce/task/reduce/Fetcher.java

@@ -23,6 +23,7 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URL;
+import java.net.HttpURLConnection;
 import java.net.URLConnection;
 import java.net.URLConnection;
 import java.util.HashSet;
 import java.util.HashSet;
 import java.util.List;
 import java.util.List;
@@ -204,7 +205,7 @@ class Fetcher<K,V> extends Thread {
     
     
     try {
     try {
       URL url = getMapOutputURL(host, maps);
       URL url = getMapOutputURL(host, maps);
-      URLConnection connection = url.openConnection();
+      HttpURLConnection connection = (HttpURLConnection)url.openConnection();
       
       
       // generate hash of the url
       // generate hash of the url
       String msgToEncode = SecureShuffleUtils.buildMsgFrom(url);
       String msgToEncode = SecureShuffleUtils.buildMsgFrom(url);
@@ -218,6 +219,14 @@ class Fetcher<K,V> extends Thread {
       connect(connection, connectionTimeout);
       connect(connection, connectionTimeout);
       connectSucceeded = true;
       connectSucceeded = true;
       input = new DataInputStream(connection.getInputStream());
       input = new DataInputStream(connection.getInputStream());
+
+      // Validate response code
+      int rc = connection.getResponseCode();
+      if (rc != HttpURLConnection.HTTP_OK) {
+        throw new IOException(
+            "Got invalid response code " + rc + " from " + url +
+            ": " + connection.getResponseMessage());
+      }
       
       
       // get the replyHash which is HMac of the encHash we sent to the server
       // get the replyHash which is HMac of the encHash we sent to the server
       String replyHash = connection.getHeaderField(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH);
       String replyHash = connection.getHeaderField(SecureShuffleUtils.HTTP_HEADER_REPLY_URL_HASH);