From e0e37d25213b6659461d679845e593bbd2d572c1 Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Thu, 19 Mar 2009 11:03:51 +0000
Subject: [PATCH]  fix for 3829 : "Severe Error" logged when dsreplication enable is used with "localhost" and hostname for --host1 and --host2    In such cases the Replication Server were not detecting that they are already connected and was keeping trying to open new connection to each other Replication Server.

---
 opends/src/server/org/opends/server/replication/server/ReplicationServer.java |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
index ff0a677..cd75b10 100644
--- a/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
+++ b/opends/src/server/org/opends/server/replication/server/ReplicationServer.java
@@ -309,10 +309,29 @@
           {
             InetAddress inetAddress = InetAddress.getByName(hostname);
             String serverAddress = inetAddress.getHostAddress() + ":" + port;
+            String alternServerAddress = null;
+            if (hostname.equalsIgnoreCase("localhost"))
+
+            {
+              // if "localhost" was used as the hostname in the configuration
+              // also check is the connection is already opened with the
+              // local address.
+              alternServerAddress =
+                InetAddress.getLocalHost().getHostAddress() + ":" + port;
+            }
+            if (inetAddress.equals(InetAddress.getLocalHost()))
+            {
+              // if the host address is the local one, also check
+              // if the connection is already opened with the "localhost"
+              // address
+              alternServerAddress = "127.0.0.1" + ":" + port;
+            }
 
             if ((serverAddress.compareTo("127.0.0.1:" + replicationPort) != 0)
                 && (serverAddress.compareTo(this.localURL) != 0)
-                && (!connectedReplServers.contains(serverAddress)))
+                && (!connectedReplServers.contains(serverAddress)
+                && ((alternServerAddress == null)
+                    || !connectedReplServers.contains(alternServerAddress))))
             {
               this.connect(serverURL, replicationServerDomain.getBaseDn());
             }

--
Gitblit v1.10.0