From 25ddfefb963cf8c83b6fc16a1c1cbed9f9368134 Mon Sep 17 00:00:00 2001 From: Sumedh Wale Date: Fri, 25 Jun 2021 20:26:49 +0530 Subject: [PATCH] skip IP address when hostname-for-clients has been provided for cases where client-bind-address is an internal IP address (behind a firewall) or 0.0.0.0 etc, then adding the IP address to hostname-for-clients specified value can result in incorrect client behaviour, so skip adding IP address for such cases updated FabricServerTest for the above change --- .../internal/engine/fabricservice/FabricServiceImpl.java | 9 +++++++-- .../gemfirexd/internal/engine/FabricServerTest.java | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/fabricservice/FabricServiceImpl.java b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/fabricservice/FabricServiceImpl.java index 62eaeaedd..0ed8172d1 100644 --- a/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/fabricservice/FabricServiceImpl.java +++ b/gemfirexd/core/src/main/java/com/pivotal/gemfirexd/internal/engine/fabricservice/FabricServiceImpl.java @@ -879,6 +879,8 @@ public abstract class NetworkInterfaceImpl implements NetworkInterface, protected InetAddress inetAddress; + protected volatile String hostNameForClients; + protected volatile String hostName; protected int port; @@ -1100,7 +1102,8 @@ public final String asString() { public final String getHostName() { final String hostName = getHostNameForClients(); if (hostName != null) { - return hostName; + return this.hostNameForClients != null ? this.hostNameForClients + : hostName + '/' + this.inetAddress.getHostAddress(); } return "/" + this.inetAddress.getHostAddress(); } @@ -1145,6 +1148,7 @@ protected final String setHostNameForClients(Properties networkProps) { Attribute.HOSTNAME_FOR_CLIENTS, GfxdConstants.GFXD_PREFIX + Attribute.HOSTNAME_FOR_CLIENTS, monitorlite); if (host != null) { + this.hostNameForClients = host; this.hostName = host; return host; } @@ -1157,7 +1161,8 @@ protected final String setHostNameForClients(Properties networkProps) { try { final InetAddress localHost = SocketCreator.getLocalHost(); if (localHost != null && !localHost.isLoopbackAddress()) { - return (this.hostName = getHostFromInetAddress(localHost)); + this.hostNameForClients = getHostFromInetAddress(localHost); + return (this.hostName = this.hostNameForClients); } } catch (UnknownHostException uhe) { // ignored diff --git a/gemfirexd/tools/src/test/java/com/pivotal/gemfirexd/internal/engine/FabricServerTest.java b/gemfirexd/tools/src/test/java/com/pivotal/gemfirexd/internal/engine/FabricServerTest.java index 1349c1c2e..256b77e13 100644 --- a/gemfirexd/tools/src/test/java/com/pivotal/gemfirexd/internal/engine/FabricServerTest.java +++ b/gemfirexd/tools/src/test/java/com/pivotal/gemfirexd/internal/engine/FabricServerTest.java @@ -914,7 +914,7 @@ public void testLocatorStartupAPI() throws Exception { } String netStr = rs.getString(3); assertTrue("Unexpected network server address " + netStr, - netStr.endsWith("/0.0.0.0[" + netPort + ']')); + netStr.endsWith("[" + netPort + ']') && !netStr.contains("/0.0.0.0")); assertFalse("expected no more than one row from SYS.MEMBERS", rs.next()); } finally { try {