From 79e812a1ce0dc5e475a57a31c1a6ac2382c5b1a9 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Wed, 28 Oct 2026 16:24:44 +0000
Subject: [PATCH] [#1241] Log the benign aborts of a replication handshake as warnings: the cross connection timeout (145) and a peer which went away (178, 179) (#1242)

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java |   56 +++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java
index 6694a9f..a6961cf 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/server/ServerHandler.java
@@ -205,11 +205,41 @@
   }
 
   /**
-   * Abort a start procedure currently establishing.
+   * Abort a start procedure currently establishing, logging the reason as an error.
    * @param reason The provided reason.
    */
   protected void abortStart(LocalizableMessage reason)
   {
+    abortStart(reason, false);
+  }
+
+  /**
+   * Abort a start procedure currently establishing, logging the reason as a warning.
+   * <p>
+   * For the aborts which are no error of this server and no fault of its peer
+   * either: the peer going away while the handshake ran, which the peer logs
+   * as a warning itself when it gave up on its own timeout, and this server
+   * giving way to a cross connection. Both are what a peer restarting under
+   * load leaves behind, and logged as errors they read as errors of every
+   * server it was handshaking with.
+   * <p>
+   * The peer going away is an {@code IOException} of the session, in either
+   * phase of the handshake. A peer silent past the connection timeout is one
+   * too: it is also what the connect thread of a cross connection reads while
+   * the listen thread of its peer waits for the domain lock. The exception is a
+   * {@link org.opends.server.replication.protocol.PacketTooLargeException}:
+   * a frame this server has no heap for is not the peer going away, and is an
+   * error.
+   *
+   * @param reason The provided reason.
+   */
+  protected void abortStartWithWarning(LocalizableMessage reason)
+  {
+    abortStart(reason, true);
+  }
+
+  private void abortStart(LocalizableMessage reason, boolean isWarning)
+  {
     // 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
     Session localSession = session;
@@ -221,7 +251,14 @@
         {
          logger.trace("In " + this + " closing session with err=" + reason);
         }
-        logger.error(reason);
+        if (isWarning)
+        {
+          logger.warn(reason);
+        }
+        else
+        {
+          logger.error(reason);
+        }
       }
 
       // This method is only called when aborting a failing handshake and
@@ -790,25 +827,18 @@
    * thread to take the lock it was waiting for and process the connection
    * attempt.
    *
-   * @throws DirectoryException
-   *           When an exception occurs.
+   * @return {@code true} if the lock was acquired, {@code false} if the wait
+   *         timed out, which is the connection attempt to abort
    * @throws InterruptedException
    *           If the current thread was interrupted while waiting for the lock.
    */
-  public void lockDomainWithTimeout() throws DirectoryException,
-      InterruptedException
+  public boolean lockDomainWithTimeout() throws InterruptedException
   {
     final Random random = new Random();
     final int randomTime = random.nextInt(6); // Random from 0 to 5
     // Wait at least 3 seconds + (0 to 5 seconds)
     final long timeout = 3000 + randomTime * 1000L;
-    final boolean lockAcquired = replicationServerDomain.tryLock(timeout);
-    if (!lockAcquired)
-    {
-      LocalizableMessage message = WARN_TIMEOUT_WHEN_CROSS_CONNECTION.get(
-          getBaseDN(), serverId, session.getReadableRemoteAddress(), getReplicationServerId());
-      throw new DirectoryException(ResultCode.OTHER, message);
-    }
+    return replicationServerDomain.tryLock(timeout);
   }
 
   /**

--
Gitblit v1.10.0