diff --git a/CHANGES.txt b/CHANGES.txt index 2c474e8844..d5d692f3ea 100644 --- a/CHANGES.txt +++ b/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 diff --git a/src/java/org/apache/hadoop/http/HttpServer.java b/src/java/org/apache/hadoop/http/HttpServer.java index 0822af2415..39dc350515 100644 --- a/src/java/org/apache/hadoop/http/HttpServer.java +++ b/src/java/org/apache/hadoop/http/HttpServer.java @@ -27,6 +27,7 @@ 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 void start() throws IOException { } //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,