You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by zh...@apache.org on 2022/06/01 23:54:11 UTC

[geode] 01/01: GEODE-10349: Client connects to a new server socket should check its availability

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

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

commit 8c3329f9e5f19abdac04d1afb592c027f852b3fa
Author: zhouxh <gz...@pivotal.io>
AuthorDate: Wed Jun 1 16:53:23 2022 -0700

    GEODE-10349: Client connects to a new server socket should check its availability
---
 .../distributed/internal/tcpserver/AdvancedSocketCreatorImpl.java   | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/AdvancedSocketCreatorImpl.java b/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/AdvancedSocketCreatorImpl.java
index 9d85ad3747..e0d82a28db 100644
--- a/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/AdvancedSocketCreatorImpl.java
+++ b/geode-tcp-server/src/main/java/org/apache/geode/distributed/internal/tcpserver/AdvancedSocketCreatorImpl.java
@@ -20,6 +20,7 @@ import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.net.UnknownHostException;
 import java.nio.channels.ServerSocketChannel;
 import java.util.concurrent.ThreadLocalRandom;
 
@@ -99,6 +100,11 @@ public class AdvancedSocketCreatorImpl implements AdvancedSocketCreator {
       }
       InetSocketAddress inetSocketAddress = addr.getSocketInetAddress();
       try {
+        if (inetSocketAddress.getAddress() == null
+            || !inetSocketAddress.getAddress().isReachable(5000)) {
+          throw new UnknownHostException(
+              inetSocketAddress.getHostName() + ":" + inetSocketAddress.getPort());
+        }
         socket.connect(inetSocketAddress, Math.max(timeout, 0));
       } catch (ConnectException connectException) {
         logger.info("Failed to connect to " + inetSocketAddress);