From 3556ad0275d7271b6533569ac72cb741abdb0b81 Mon Sep 17 00:00:00 2001
From: gbellato <gbellato@localhost>
Date: Thu, 03 Jan 2008 14:00:38 +0000
Subject: [PATCH]  fix for 2787 : Replication Server sessions fails when disconnecting and re-connecting   When a ReplicationBroker disconnect and reconnect quickly to a Replication Server the reconnection sometimes fails.

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

diff --git a/opends/src/server/org/opends/server/replication/server/ServerHandler.java b/opends/src/server/org/opends/server/replication/server/ServerHandler.java
index cd499e3..fb71b78 100644
--- a/opends/src/server/org/opends/server/replication/server/ServerHandler.java
+++ b/opends/src/server/org/opends/server/replication/server/ServerHandler.java
@@ -283,6 +283,10 @@
         // Get or Create the ReplicationServerDomain
         replicationServerDomain =
                 replicationServer.getReplicationServerDomain(this.baseDn, true);
+
+        replicationServerDomain.waitDisconnection(receivedMsg.getServerId());
+        replicationServerDomain.mayResetGenerationId();
+
         localGenerationId = replicationServerDomain.getGenerationId();
 
         ServerState localServerState =
@@ -1010,16 +1014,18 @@
       {
       }
     }
-    do {
+    boolean acquired = false;
+    do
+    {
       try
       {
-        sendWindow.tryAcquire((long)500, TimeUnit.MILLISECONDS);
+        acquired = sendWindow.tryAcquire((long)500, TimeUnit.MILLISECONDS);
         interrupted = false;
       } catch (InterruptedException e)
       {
         // loop until not interrupted
       }
-    } while ((interrupted) && (!shutdown));
+    } while (((interrupted) || (!acquired )) && (!shutdown));
     this.incrementOutCount();
     return msg;
   }
@@ -1800,6 +1806,17 @@
   }
 
   /**
+   * Send an ErrorMessage to the peer.
+   *
+   * @param errorMsg The message to be sent
+   * @throws IOException when raised by the underlying session
+   */
+  public void sendError(ErrorMessage errorMsg) throws IOException
+  {
+    session.publish(errorMsg);
+  }
+
+  /**
    * Process the reception of a WindowProbe message.
    *
    * @param  windowProbeMsg The message to process.

--
Gitblit v1.10.0