From 005b222484780397493d246be89c831734393fca Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Sat, 21 Nov 2026 08:53:02 +0000
Subject: [PATCH] [#1310] Limit OpenDJ helper JVM heaps (#1312)

---
 opendj-server-legacy/resource/bin/start-ds.bat       |   28 ++++++++++++++++++++++++----
 opendj-server-legacy/resource/config/java.properties |    2 +-
 opendj-server-legacy/resource/bin/stop-ds.bat        |    7 ++++++-
 opendj-packages/opendj-docker/healthcheck.sh         |    6 +++++-
 opendj-server-legacy/resource/bin/_script-util.sh    |    6 ++++++
 opendj-server-legacy/resource/bin/start-ds           |    4 ++--
 opendj-server-legacy/resource/bin/stop-ds            |    5 +++--
 7 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/opendj-packages/opendj-docker/healthcheck.sh b/opendj-packages/opendj-docker/healthcheck.sh
index a623a31..ae30992 100755
--- a/opendj-packages/opendj-docker/healthcheck.sh
+++ b/opendj-packages/opendj-docker/healthcheck.sh
@@ -40,5 +40,9 @@
   BIND_ARGS=(--bindDN "${HEALTHCHECK_BIND_DN}" --bindPasswordFile "${HEALTHCHECK_BIND_PASSWORD_FILE}")
 fi
 
-/opt/opendj/bin/ldapsearch --noPropertiesFile --hostname localhost --port "${LDAPS_PORT:-1636}" --useSsl --trustAll \
+# Skip launching the LDAP client while the LDAPS listener is down.
+port=${LDAPS_PORT:-1636}
+: 2>/dev/null <"/dev/tcp/localhost/${port}" || exit 1
+
+/opt/opendj/bin/ldapsearch --noPropertiesFile --hostname localhost --port "${port}" --useSsl --trustAll \
   "${BIND_ARGS[@]}" --baseDN "" --searchScope base "(objectClass=*)" 1.1 || exit 1
diff --git a/opendj-server-legacy/resource/bin/_script-util.sh b/opendj-server-legacy/resource/bin/_script-util.sh
index 6eaff75..09ab895 100644
--- a/opendj-server-legacy/resource/bin/_script-util.sh
+++ b/opendj-server-legacy/resource/bin/_script-util.sh
@@ -177,6 +177,12 @@
   fi
 }
 
+# Give the lifecycle waiter its own heap without changing other Java launches.
+wait_for_file_delete() (
+  unset JAVA_TOOL_OPTIONS JDK_JAVA_OPTIONS _JAVA_OPTIONS
+  exec "${OPENDJ_JAVA_BIN}" -client -Xmx16m org.opends.server.tools.WaitForFileDelete "$@"
+)
+
 print_error_message() {
   if test -z "${OPENDJ_JAVA_BIN}"
   then
diff --git a/opendj-server-legacy/resource/bin/start-ds b/opendj-server-legacy/resource/bin/start-ds
index 8e3d032..49e7817 100644
--- a/opendj-server-legacy/resource/bin/start-ds
+++ b/opendj-server-legacy/resource/bin/start-ds
@@ -106,10 +106,10 @@
   echo $! > "${PID_FILE}"
   if test ${EC} -eq 99
   then
-    "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
+    wait_for_file_delete \
          --targetFile "${STARTING_FILE}" --logFile "${LOG_FILE}" "${@}"
   else
-    "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
+    wait_for_file_delete \
          --targetFile "${STARTING_FILE}" "${@}"
   fi
   EC=${?}
diff --git a/opendj-server-legacy/resource/bin/start-ds.bat b/opendj-server-legacy/resource/bin/start-ds.bat
index 905e7e8..9b9b4c6 100644
--- a/opendj-server-legacy/resource/bin/start-ds.bat
+++ b/opendj-server-legacy/resource/bin/start-ds.bat
@@ -113,7 +113,12 @@
 if exist "%INSTANCE_ROOT%\lib\set-java-args.bat" DO call "%INSTANCE_ROOT%\lib\set-java-args.bat"
 "%INSTALL_ROOT%\lib\winlauncher.exe" start "%INSTANCE_ROOT%" "%OPENDJ_JAVA_BIN%" %OPENDJ_JAVA_ARGS%  %SCRIPT_NAME_ARG% org.opends.server.core.DirectoryServer --configFile "%INSTANCE_ROOT%\config\config.ldif" %*
 echo %SCRIPT%: Waiting for "%INSTANCE_ROOT%\logs\server.starting" to be deleted >> %LOG%
-"%OPENDJ_JAVA_BIN%" -client org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.starting" --logFile "%INSTANCE_ROOT%\logs\server.out" %*
+setlocal
+set "JAVA_TOOL_OPTIONS="
+set "JDK_JAVA_OPTIONS="
+set "_JAVA_OPTIONS="
+"%OPENDJ_JAVA_BIN%" -client -Xmx16m org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.starting" --logFile "%INSTANCE_ROOT%\logs\server.out" %*
+endlocal
 goto checkStarted
 
 :runDetachQuiet
@@ -123,7 +128,12 @@
 if exist "%INSTANCE_ROOT%\lib\set-java-args.bat" DO call "%INSTANCE_ROOT%\lib\set-java-args.bat"
 "%INSTALL_ROOT%\lib\winlauncher.exe" start "%INSTANCE_ROOT%" "%OPENDJ_JAVA_BIN%" %OPENDJ_JAVA_ARGS%  %SCRIPT_NAME_ARG% org.opends.server.core.DirectoryServer --configFile "%INSTANCE_ROOT%\config\config.ldif" %*
 echo %SCRIPT%: Waiting for "%INSTANCE_ROOT%\logs\server.starting" to be deleted >> %LOG%
-"%OPENDJ_JAVA_BIN%" -client org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.starting" --logFile "%INSTANCE_ROOT%\logs\server.out" %* >> %LOG%
+setlocal
+set "JAVA_TOOL_OPTIONS="
+set "JDK_JAVA_OPTIONS="
+set "_JAVA_OPTIONS="
+"%OPENDJ_JAVA_BIN%" -client -Xmx16m org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.starting" --logFile "%INSTANCE_ROOT%\logs\server.out" %* >> %LOG%
+endlocal
 goto checkStarted
 
 :runDetachCalledByWinService
@@ -136,7 +146,12 @@
 if exist "%INSTANCE_ROOT%\lib\set-java-args.bat" DO call "%INSTANCE_ROOT%\lib\set-java-args.bat"
 "%INSTALL_ROOT%\lib\winlauncher.exe" start "%INSTANCE_ROOT%" "%OPENDJ_JAVA_BIN%" -Xrs %OPENDJ_JAVA_ARGS% %SCRIPT_NAME_ARG% org.opends.server.core.DirectoryServer --configFile "%INSTANCE_ROOT%\config\config.ldif" %*
 echo %SCRIPT%: Waiting for "%INSTANCE_ROOT%\logs\server.starting" to be deleted >> %LOG%
-"%OPENDJ_JAVA_BIN%" -client org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.starting" --logFile "%INSTANCE_ROOT%\logs\server.out" --outputFile "%INSTANCE_ROOT%\logs\winservice.out" %*
+setlocal
+set "JAVA_TOOL_OPTIONS="
+set "JDK_JAVA_OPTIONS="
+set "_JAVA_OPTIONS="
+"%OPENDJ_JAVA_BIN%" -client -Xmx16m org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.starting" --logFile "%INSTANCE_ROOT%\logs\server.out" --outputFile "%INSTANCE_ROOT%\logs\winservice.out" %*
+endlocal
 erase "%INSTANCE_ROOT%\logs\server.startingservice"
 goto checkStarted
 
@@ -144,7 +159,12 @@
 echo %SCRIPT%: Run as service >> %LOG%
 "%OPENDJ_JAVA_BIN%" -client org.opends.server.tools.StartWindowsService
 echo %SCRIPT%: Waiting for "%INSTANCE_ROOT%\logs\server.startingservice" to be deleted >> %LOG%
-"%OPENDJ_JAVA_BIN%" -client org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.startingservice" %*
+setlocal
+set "JAVA_TOOL_OPTIONS="
+set "JDK_JAVA_OPTIONS="
+set "_JAVA_OPTIONS="
+"%OPENDJ_JAVA_BIN%" -client -Xmx16m org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.startingservice" %*
+endlocal
 rem Type the contents the winwervice.out file and delete it.
 if exist "%INSTANCE_ROOT%\logs\winservice.out" type "%INSTANCE_ROOT%\logs\winservice.out"
 if exist "%INSTANCE_ROOT%\logs\winservice.out" erase "%INSTANCE_ROOT%\logs\winservice.out"
diff --git a/opendj-server-legacy/resource/bin/stop-ds b/opendj-server-legacy/resource/bin/stop-ds
index 4af0007..7293b3b 100644
--- a/opendj-server-legacy/resource/bin/stop-ds
+++ b/opendj-server-legacy/resource/bin/stop-ds
@@ -14,6 +14,7 @@
 #
 # Copyright 2006-2009 Sun Microsystems, Inc.
 # Portions Copyright 2011-2014 ForgeRock AS.
+# Portions Copyright 2026 3A Systems, LLC.
 
 
 # This script may be used to request that the Directory Server shut down.
@@ -165,11 +166,11 @@
     then
       if test ${QUIET_OPTION} -eq 0
       then
-        "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
+        wait_for_file_delete \
             --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
             --logFile "${INSTANCE_ROOT}/logs/errors"
       else
-        "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
+        wait_for_file_delete \
             --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
             --logFile "${INSTANCE_ROOT}/logs/errors"  --quiet
       fi
diff --git a/opendj-server-legacy/resource/bin/stop-ds.bat b/opendj-server-legacy/resource/bin/stop-ds.bat
index 8848999..647e986 100644
--- a/opendj-server-legacy/resource/bin/stop-ds.bat
+++ b/opendj-server-legacy/resource/bin/stop-ds.bat
@@ -126,7 +126,12 @@
 if not %errorlevel% == 0 goto end
 echo %SCRIPT%: restart as windows service, starting >> %LOG%
 "%OPENDJ_JAVA_BIN%" -client org.opends.server.tools.StartWindowsService
-"%OPENDJ_JAVA_BIN%" -client org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.startingservice"
+setlocal
+set "JAVA_TOOL_OPTIONS="
+set "JDK_JAVA_OPTIONS="
+set "_JAVA_OPTIONS="
+"%OPENDJ_JAVA_BIN%" -client -Xmx16m org.opends.server.tools.WaitForFileDelete --targetFile "%INSTANCE_ROOT%\logs\server.startingservice"
+endlocal
 rem Type the contents the winwervice.out file and delete it.
 if exist "%INSTANCE_ROOT%\logs\winservice.out" type "%INSTANCE_ROOT%\logs\winservice.out"
 if exist "%INSTANCE_ROOT%\logs\winservice.out" erase "%INSTANCE_ROOT%\logs\winservice.out"
diff --git a/opendj-server-legacy/resource/config/java.properties b/opendj-server-legacy/resource/config/java.properties
index a93d988..723c111 100644
--- a/opendj-server-legacy/resource/config/java.properties
+++ b/opendj-server-legacy/resource/config/java.properties
@@ -12,7 +12,7 @@
 #
 # Copyright 2008-2010 Sun Microsystems, Inc.
 # Portions Copyright 2011-2016 ForgeRock AS.
-# Portions Copyright 2018- 3A Systems LLC.
+# Portions Copyright 2018-2026 3A Systems, LLC.
 #
 # This file contains the java properties that the different command lines will
 # use when launched.  You can specify the location of the java binaries to be

--
Gitblit v1.10.0