PR comments, do explicit setReuseAddress(false)
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/3eb74a56 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/3eb74a56 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/3eb74a56 Branch: refs/heads/master Commit: 3eb74a5667a20f1092b4d426a1d327e5a97d68f7 Parents: 80322eb Author: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Authored: Sat Feb 18 00:54:59 2017 +0000 Committer: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Committed: Wed Mar 1 08:54:55 2017 +0000 ---------------------------------------------------------------------- .../apache/brooklyn/launcher/BrooklynWebServer.java | 3 +-- .../java/org/apache/brooklyn/util/net/Networking.java | 14 ++++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3eb74a56/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java ---------------------------------------------------------------------- diff --git a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java index e5c6b15..b85e79d 100644 --- a/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java +++ b/launcher/src/main/java/org/apache/brooklyn/launcher/BrooklynWebServer.java @@ -453,8 +453,7 @@ public class BrooklynWebServer { try { server.start(); } catch (BindException e) { - // port discovery routines may take some time to clear, e.g. 250ms for SO_TIMEOUT - // tests fail because of this; see if adding a delay improves things + // retry once just in case it was some fluke or race log.warn("Initial server start-up failed binding (retrying after a delay): "+e); Time.sleep(Duration.millis(500)); server.start(); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3eb74a56/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java ---------------------------------------------------------------------- diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java b/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java index 028b3c8..79e3739 100644 --- a/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java +++ b/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java @@ -66,6 +66,10 @@ public class Networking { public static final int MIN_PORT_NUMBER = 1; public static final int MAX_PORT_NUMBER = 65535; + // set this `false` because not all routines that want a port will be as forgiving as reuse_address is; + // in some cases it might be preferable for this to be true, if needed we can expand API + public static final Boolean SET_REUSE_ADDRESS = false; + // based on http://stackoverflow.com/questions/106179/regular-expression-to-match-hostname-or-ip-address // but updated to allow leading zeroes public static final String VALID_IP_ADDRESS_REGEX = "^((0*[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}(0*[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"; @@ -102,15 +106,13 @@ public class Networking { // Check TCP port ss = new ServerSocket(); ss.setSoTimeout(250); - ss.setReuseAddress(true); - if (!ss.getReuseAddress()) { logReuseAddressNotSupported(); } + if (SET_REUSE_ADDRESS!=null) { ss.setReuseAddress(SET_REUSE_ADDRESS); } ss.bind(new InetSocketAddress(localAddress, port)); // Check UDP port ds = new DatagramSocket(null); ds.setSoTimeout(250); - ds.setReuseAddress(true); - if (!ds.getReuseAddress()) { logReuseAddressNotSupported(); } + if (SET_REUSE_ADDRESS!=null) { ss.setReuseAddress(SET_REUSE_ADDRESS); } ds.bind(new InetSocketAddress(localAddress, port)); } catch (IOException e) { if (log.isTraceEnabled()) log.trace("Failed binding to " + localAddress + " : " + port, e); @@ -178,10 +180,6 @@ public class Networking { } } - private static void logReuseAddressNotSupported() { - log.debug("Socket reuse-address not supported on this platform; port discovery may mis-report available ports"); - } - /** * Bind to the specified IP, but let the OS pick a port. * If the operation fails we know it's not because of