Browse Source

HADOOP-6386. NameNode's HttpServer can't instantiate InetSocketAddress: IllegalArgumentException is thrown. Contributed by Konstantin Boudnik.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@888565 13f79535-47bb-0310-9956-ffa450edef68
Konstantin Boudnik 15 years ago
parent
commit
929e91a08c
2 changed files with 31 additions and 0 deletions
  1. 3 0
      CHANGES.txt
  2. 28 0
      src/java/org/apache/hadoop/http/HttpServer.java

+ 3 - 0
CHANGES.txt

@@ -59,6 +59,9 @@ Trunk (unreleased changes)
 
     HADOOP-6411. Remove deprecated file src/test/hadoop-site.xml. (cos)
 
+    HADOOP-6386. NameNode's HttpServer can't instantiate InetSocketAddress:
+    IllegalArgumentException is thrown (cos)
+
 Release 0.21.0 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 28 - 0
src/java/org/apache/hadoop/http/HttpServer.java

@@ -27,6 +27,7 @@ import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Random;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -469,6 +470,33 @@ public class HttpServer implements FilterContainer {
           } //Workaround end
           LOG.info("Jetty bound to port " + port);
           webServer.start();
+          // Workaround for HADOOP-6386
+          port = listener.getLocalPort();
+          if (port < 0) {
+            LOG.warn("Bounds port is " + port + " after webserver start");
+            Random r = new Random(1000);
+            for (int i = 0; i < MAX_RETRIES/2; i++) {
+              try {
+                webServer.stop();
+              } catch (Exception e) {
+                LOG.warn("Can't stop  web-server", e);
+              }
+              Thread.sleep(r.nextInt());
+              
+              listener.setPort(oriPort == 0 ? 0 : (oriPort += 1));
+              listener.open();
+              Thread.sleep(100);
+              webServer.start();
+              LOG.info(i + "attempts to restart webserver");
+              port = listener.getLocalPort();
+              if (port > 0)
+                break;
+            }
+            if (port < 0)
+              throw new Exception("listener.getLocalPort() is returning " +
+                		"less than 0 even after " +MAX_RETRIES+" resets");
+          }
+          // End of HADOOP-6386 workaround
           break;
         } catch (IOException ex) {
           // if this is a bind exception,