fix: retry loop for Windows Service start race condition (issue #259)#609
Draft
fix: retry loop for Windows Service start race condition (issue #259)#609
Conversation
…fix Windows Service startup race condition (#259) Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/bda703f7-83cc-4cf1-816a-65b26d4b8917 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix race condition in doStartApplication for Windows service startup
fix: retry loop for Windows Service start race condition (issue #259)
Mar 31, 2026
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/5f9bd204-2761-4f54-97e1-b16d021b5fe0 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Portions Copyright 2026 3A Systems, LLC.to the copyright header of the modified fileopendj-server-legacy/src/build-tools/windows/service.cOriginal prompt
Problem
Issue: #259
OpenDJ 4.5 fails to start as a Windows Service on Windows 11 21H2. The service stops a few seconds after starting with the error:
Root Cause
In
opendj-server-legacy/src/build-tools/windows/service.c, thedoStartApplication()function has a race condition. Whenstart-ds.batis invoked with--windowsNetStart, the following sequence occurs:opendj_service.exelaunchesstart-ds.bat --windowsNetStartstart-ds.batcalls--checkStartabilitywhich returns code102(START_AS_DETACH_CALLED_FROM_WINDOWS_SERVICE)winlauncher.exespawns the Java DirectoryServer process in the background (background=1) and immediately returns the PIDstart-ds.batwaits forserver.startingfile to be deleted, then does a--checkStartabilitycheck and exits with code 0opendj_service.exeseeswaitForProcesssucceeded with exitCode=0, so bothcreateOkandwaitOkareTRUEif (createOk && waitOk)branch (around line 566), the code checksisServerRunning()only once — no retry loopserver.lock, soisServerRunning()returnsFALSEIn contrast, the
else if (createOk)branch (when the wait times out) does have a retry loop with up to 100 tries and 5-second sleep intervals. ThecreateOk && waitOkbranch incorrectly assumes that ifstart-ds.batexited successfully, the Java server must already hold the lock — but on Windows 11 (and potentially other systems), the JVM startup is slow enough that this assumption fails.Required Fix
Replace the single
isServerRunning()check in theif (createOk && waitOk)branch with a retry loop similar to the one in theelse if (createOk)branch. This ensures the service controller waits for the Java process to actually acquire the server lock before declaring failure.The fix should be in file
opendj-server-legacy/src/build-tools/windows/service.cin thedoStartApplication()function.Find this block (approximately lines 563-580):
And replace it with:
This change makes both branches of
doStartApplication()consistently use a retry loop, controlled by the sameOPENDJ_WINDOWS_SERVICE_START_NTRIESenvironment variable.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: проанализируй
Assistant:
Let me analyze this issue by examining the relevant code in the repository.
Assistant: ## Анализ Issue #259: OpenDJ 4.5 не стартует как Windows Service на Windows 11
Корневая причина (Root Cause)
Проблема заключается в гонке состояний (race condition) между Java-процессом сервера и нативным Windows-сервис-контроллером (`opendj_servic...
This pull request was created from Copilot chat.