From 80774bcd0c732d9446cfc09fc9b7c39a3e4003ad Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 23 Mar 2011 22:27:01 +0000
Subject: [PATCH] Fix issue OpenDJ-95: Socket leak and constant disconnect/reconnect when a directory server can no longer reach its connected replication server

---
 opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java |   44 +++++++++++---------------------------------
 1 files changed, 11 insertions(+), 33 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java b/opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java
index 631d578..4c3f132 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/replication/server/ServerHandler.java
@@ -63,7 +63,6 @@
 import org.opends.server.replication.protocol.StartECLSessionMsg;
 import org.opends.server.replication.protocol.StartMsg;
 import org.opends.server.replication.protocol.StartSessionMsg;
-import org.opends.server.replication.protocol.StopMsg;
 import org.opends.server.replication.protocol.TopologyMsg;
 import org.opends.server.replication.protocol.UpdateMsg;
 import org.opends.server.replication.protocol.WindowMsg;
@@ -107,17 +106,14 @@
           providedMsg.toString());
       logError(providedMsg);
     }
-    try
+
+    if (providedSession != null)
     {
-      if (providedSession != null)
-        // This method is only called when aborting a failing handshake and
-        // not StopMsg should be sent in such situation. StopMsg are only
-        // expected when full handshake has been performed, or at end of
-        // handshake phase 1, when DS was just gathering available RS info
-        providedSession.close();
-    } catch (IOException e)
-    {
-      // ignore
+      // This method is only called when aborting a failing handshake and
+      // not StopMsg should be sent in such situation. StopMsg are only
+      // expected when full handshake has been performed, or at end of
+      // handshake phase 1, when DS was just gathering available RS info
+      providedSession.close();
     }
   }
 
@@ -286,9 +282,10 @@
     // We did not recognize the message, close session as what
     // can happen after is undetermined and we do not want the server to
     // be disturbed
-    if (session!=null)
+    ProtocolSession localSession = session;
+    if (localSession != null)
     {
-      closeSession(session, reason, this);
+      closeSession(localSession, reason, this);
     }
 
     if ((replicationServerDomain != null) &&
@@ -1101,26 +1098,7 @@
 
     if (session != null)
     {
-      if (protocolVersion >= ProtocolVersion.REPLICATION_PROTOCOL_V4)
-      {
-        // V4 protocol introduces a StopMsg to properly end
-        // communications
-        try
-        {
-          session.publish(new StopMsg());
-        } catch (IOException ioe)
-        {
-          // Anyway, going to close session, so nothing to do
-        }
-      }
-      // Close session to end ServerReader or ServerWriter
-      try
-      {
-        session.close();
-      } catch (IOException e)
-      {
-        // ignore.
-      }
+      session.close();
     }
 
     /*

--
Gitblit v1.10.0