From f82d22de94de20cb44775530e934eb8c26368484 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Tue, 01 Dec 2026 17:06:15 +0000
Subject: [PATCH] Stabilize replication failover and heartbeat timeout tests (#1353)

---
 opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/ReplSessionSecurity.java |   29 ++++++++++++++++++++++++++---
 1 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/ReplSessionSecurity.java b/opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/ReplSessionSecurity.java
index 1629e83..8ff859e 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/ReplSessionSecurity.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/replication/protocol/ReplSessionSecurity.java
@@ -267,7 +267,7 @@
    *          The connected socket.
    * @param soTimeout
    *          The socket timeout option to use for the protocol session.
-   * @return The new protocol session.
+   * @return The new protocol session, or {@code null} if TLS negotiation raised an {@link SSLException}.
    * @throws ConfigException
    *           If the protocol session could not be established due to a
    *           configuration problem.
@@ -278,6 +278,28 @@
   public Session createServerSession(final Socket socket,
       final int soTimeout) throws ConfigException, IOException
   {
+    try
+    {
+      return createServerSessionOrThrow(socket, soTimeout);
+    }
+    catch (SSLException e)
+    {
+      // The TLS failure was logged before the socket was closed.
+      return null;
+    }
+  }
+
+  /**
+   * Creates a server session and propagates TLS failures to the caller.
+   *
+   * @param socket the connected socket
+   * @param soTimeout the socket read timeout in milliseconds
+   * @return the new protocol session
+   * @throws ConfigException if the session configuration is invalid
+   * @throws IOException if the session cannot be established, including an {@link SSLException} from TLS negotiation
+   */
+  public Session createServerSessionOrThrow(final Socket socket, final int soTimeout) throws ConfigException, IOException
+  {
     boolean hasCompleted = false;
     SSLSocket secureSocket = null;
 
@@ -307,8 +329,9 @@
 
       // Force TLS negotiation now.
       secureSocket.startHandshake();
+      final Session session = new Session(socket, secureSocket);
       hasCompleted = true;
-      return new Session(socket, secureSocket);
+      return session;
     }
     catch (final SSLException e)
     {
@@ -316,7 +339,7 @@
       // also how a certificate misconfiguration shows up, so warn the
       // administrator instead of failing silently.
       logHandshakeFailure(socket, e);
-      return null;
+      throw e;
     }
     finally
     {

--
Gitblit v1.10.0