mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Valery Kharseko
12 hours ago 005b222484780397493d246be89c831734393fca
[#1310] Limit OpenDJ helper JVM heaps (#1312)

## Motivation

Helper JVMs run alongside the directory server during lifecycle
operations and Docker health checks. They can contribute to memory
pressure in small containers. The released Alpine image has timed out
during bootstrap in the 512 MiB upgrade test. [Example CI
run](https://github.com/OpenIdentityPlatform/OpenDJ/actions/runs/44271307242/job/134808614378)

## Changes

- Cap `WaitForFileDelete` at 16 MiB in the Unix and Windows start and
stop launchers. Clear `JAVA_TOOL_OPTIONS`, `JDK_JAVA_OPTIONS`, and
`_JAVA_OPTIONS` for the waiter invocation. Server launches and
subsequent lifecycle checks still receive their configured JVM options.
- Check the bootstrap marker and the local LDAPS TCP port before
launching the Docker health check's LDAP client. The root-DSE search
inherits the configured JVM options, including Java security and TLS
settings.
- Preserve the packaged `ldapsearch` launcher argument precedence. With
no command-specific property, the Unix launcher uses `default.java-args`
when JVM arguments are configured through `java.properties`.

#1319 handles removing the Unix detached-start waiter and reporting
early server exit.

## Validation

- Exercised Unix start, stop, and restart in normal and quiet modes with
the real waiter on JDK 21. Each waiter had a 16 MiB maximum, and the
server fixture received its original JVM environment.
- Exercised all five Windows waiter invocations with JDK 11 under Wine.
Each used a 16 MiB maximum and restored the surrounding JVM environment.
- Ran the updated health check against the default and Alpine OpenDJ
5.2.0 images. A missing bootstrap marker or a closed port returned `1`
before LDAP. The root-DSE search succeeded with configured TLS 1.2 and
inherited heap settings, including a 128 MiB soft maximum. A valid
optional bind passed and an invalid bind returned `1`.
- Verified with packaged `ldapsearch --help` on JDK 21 that a custom
`default.java-args` produced the configured 256 MiB initial heap and 512
MiB maximum.
- Bootstrap stability at 512 MiB remains unverified for this revision.

Fixes #1310
7 files modified
58 ■■■■■ changed files
opendj-packages/opendj-docker/healthcheck.sh 6 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/resource/bin/_script-util.sh 6 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/resource/bin/start-ds 4 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/resource/bin/start-ds.bat 28 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/resource/bin/stop-ds 5 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/resource/bin/stop-ds.bat 7 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/resource/config/java.properties 2 ●●●●● patch | view | raw | blame | history
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
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
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=${?}
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"
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
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"
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