From f70033e6e7a8456a8a892c4b48663cde7de82712 Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Tue, 21 Jul 2026 07:25:00 +0000
Subject: [PATCH] [#755] wait for the LDAP listener after in-process server (re)start (#756)

---
 opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPConnectionHandler.java |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPConnectionHandler.java b/opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
index c584f27..37a3256 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
@@ -13,6 +13,7 @@
  *
  * Copyright 2006-2010 Sun Microsystems, Inc.
  * Portions Copyright 2011-2016 ForgeRock AS.
+ * Portions Copyrighted 2026 3A Systems, LLC.
  */
 package org.opends.server.protocols.ldap;
 
@@ -183,6 +184,14 @@
    */
   private final Object waitListen = new Object();
 
+  /**
+   * Condition predicate for {@link #waitListen}: set once the selector thread
+   * has attempted to open the listen channels (successfully or not). Guarded
+   * by the {@link #waitListen} monitor; protects the start method against
+   * spurious wakeups.
+   */
+  private boolean listenAttempted;
+
   /** The friendly name of this connection handler. */
   private String friendlyName;
 
@@ -814,12 +823,16 @@
 
       try
       {
-        waitListen.wait();
+        while (!listenAttempted)
+        {
+          waitListen.wait();
+        }
       }
       catch (InterruptedException e)
       {
         // If something interrupted the start its probably better
         // to return ASAP.
+        Thread.currentThread().interrupt();
       }
     }
   }
@@ -859,6 +872,7 @@
           synchronized (waitListen)
           {
             starting = false;
+            listenAttempted = true;
             waitListen.notify();
           }
         }
@@ -882,6 +896,7 @@
         // should be notified and resume its work in any cases.
         synchronized (waitListen)
         {
+          listenAttempted = true;
           waitListen.notify();
         }
 

--
Gitblit v1.10.0