Browse Source

HADOOP-4744. Workaround for jetty6 returning -1 when getLocalPort is invoked on the connector. The workaround patch takes the most conservative approach of killing the server process whenever this is true. Contributed by Devaraj Das.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@746968 13f79535-47bb-0310-9956-ffa450edef68
Devaraj Das 16 years ago
parent
commit
ee99d5cd93
2 changed files with 14 additions and 1 deletions
  1. 4 0
      CHANGES.txt
  2. 10 1
      src/core/org/apache/hadoop/http/HttpServer.java

+ 4 - 0
CHANGES.txt

@@ -857,6 +857,10 @@ Release 0.20.0 - Unreleased
     HADOOP-5142. Fix MapWritable#putAll to store key/value classes. 
     (Doğacan Güney via enis)
 
+    HADOOP-4744. Workaround for jetty6 returning -1 when getLocalPort is invoked on
+    the connector. The workaround patch takes the most conservative approach of 
+    killing the server process whenever this is true. (ddas)
+
 Release 0.19.1 - Unreleased
 
   IMPROVEMENTS

+ 10 - 1
src/core/org/apache/hadoop/http/HttpServer.java

@@ -26,6 +26,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.nio.channels.ServerSocketChannel;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -340,7 +341,15 @@ public class HttpServer implements FilterContainer {
    * @return the port
    */
   public int getPort() {
-    return webServer.getConnectors()[0].getLocalPort();
+    int port = webServer.getConnectors()[0].getLocalPort();
+    if (port < 0) {
+      LOG.warn("Exiting since getLocalPort returned " + port + 
+               " Open status of jetty connector is: " +
+      (((ServerSocketChannel)webServer.getConnectors()[0].getConnection()).
+                                                    isOpen()));
+      System.exit(-1);
+    }
+    return port;
   }
 
   /**