You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2019/05/21 23:23:28 UTC

[geode] 01/01: GEODE-6789 locator fails to start even though ports in membership-port-range are available

This is an automated email from the ASF dual-hosted git repository.

bschuchardt pushed a commit to branch feature/GEODE-6789
in repository https://gitbox.apache.org/repos/asf/geode.git

commit ffe00a46cf2a04d32fb8fbe5c319dab993b26053
Author: Bruce Schuchardt <bs...@pivotal.io>
AuthorDate: Tue May 21 16:20:47 2019 -0700

    GEODE-6789 locator fails to start even though ports in membership-port-range are available
    
    Do not rely on exception text to determine whether a bind() operation
    failed.  Instead, treat all SocketAcceptions thrown by server socket
    creation a failure to bind to an inet socket address.
---
 .../geode/internal/cache/tier/sockets/AcceptorImpl.java | 14 ++------------
 .../org/apache/geode/internal/net/SocketCreator.java    | 17 ++++-------------
 2 files changed, 6 insertions(+), 25 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
index 7f6cef3..d192dc6 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/AcceptorImpl.java
@@ -23,7 +23,6 @@ import java.io.EOFException;
 import java.io.IOException;
 import java.io.InterruptedIOException;
 import java.io.OutputStream;
-import java.net.BindException;
 import java.net.Inet6Address;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
@@ -525,7 +524,7 @@ public class AcceptorImpl implements Acceptor, Runnable {
             serverSock.bind(new InetSocketAddress(getBindAddress(), port), backLog);
             break;
           } catch (SocketException b) {
-            if (!treatAsBindException(b) || System.currentTimeMillis() > tilt) {
+            if (System.currentTimeMillis() > tilt) {
               throw b;
             }
           }
@@ -555,7 +554,7 @@ public class AcceptorImpl implements Acceptor, Runnable {
                 this.gatewayTransportFilters, socketBufferSize);
             break;
           } catch (SocketException e) {
-            if (!treatAsBindException(e) || System.currentTimeMillis() > tilt) {
+            if (System.currentTimeMillis() > tilt) {
               throw e;
             }
           }
@@ -1818,15 +1817,6 @@ public class AcceptorImpl implements Acceptor, Runnable {
     return gatewayTransportFilters;
   }
 
-  // IBM J9 sometimes reports "listen failed" instead of BindException
-  private static boolean treatAsBindException(SocketException se) {
-    if (se instanceof BindException) {
-      return true;
-    }
-    final String msg = se.getMessage();
-    return msg != null && msg.contains("Invalid argument: listen failed");
-  }
-
   static boolean isAuthenticationRequired() {
     return isAuthenticationRequired;
   }
diff --git a/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java b/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java
index bc136f5..23dc6a6 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/net/SocketCreator.java
@@ -774,8 +774,8 @@ public class SocketCreator {
               "Unable to find a free port in the membership-port-range");
         }
       }
+      ServerSocket socket = null;
       try {
-        ServerSocket socket;
         if (useNIO) {
           ServerSocketChannel channel = ServerSocketChannel.open();
           socket = channel.socket();
@@ -788,23 +788,14 @@ public class SocketCreator {
         }
         return socket;
       } catch (java.net.SocketException ex) {
-        if (useNIO || SocketCreator.treatAsBindException(ex)) {
-          localPort++;
-        } else {
-          throw ex;
+        if (socket != null && !socket.isClosed()) {
+          socket.close();
         }
+        localPort++;
       }
     }
   }
 
-  private static boolean treatAsBindException(SocketException se) {
-    if (se instanceof BindException) {
-      return true;
-    }
-    final String msg = se.getMessage();
-    return (msg != null && msg.contains("Invalid argument: listen failed"));
-  }
-
   /**
    * Return a client socket. This method is used by client/server clients.
    */