From 959bfadea9edec29a02b5f58562b774ffaa530fa 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 --- .../gemfire/internal/cache/AbstractRegionMap.java | 2 +- .../internal/engine/fabricservice/FabricServiceImpl.java | 9 +++++++-- .../gemfirexd/internal/engine/FabricServerTest.java | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java index 89be5a2a7..b9baa164f 100644 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegionMap.java @@ -4130,7 +4130,7 @@ else if (re != null && owner.isUsedForPartitionedRegionBucket()) { // No need here to close the region etc, the asynch shutdown thread spawned in diskstore will do // Moreover for non tx threads this exception is not expected, for Tx threads let this exception // cause rollback - assert noTxn; + // assert noTxn; result = null; //owner.handleDiskAccessException(dae, true/* stop bridge servers*/); throw dae; 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 {