Fix infinite loop in doStopApplication() on Windows service stop#610
Draft
Fix infinite loop in doStopApplication() on Windows service stop#610
doStopApplication() on Windows service stop#610Conversation
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/b8d7e4b7-e6e7-45c5-b70c-b90833a88d84 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/a07e721d-23f2-4511-976c-3682f3473369 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/e46b6ae6-67e4-4df3-a718-14eb1853fc33 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix infinite loop in doStopApplication function
Fix infinite loop in Mar 31, 2026
doStopApplication() on Windows service stop
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/9c943d96-6413-42b0-9380-3e3e6186a45d Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/00df5340-a338-444c-a9a7-92f4f2a0dd7e Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/7a28df62-1005-4859-8e60-7f15511a9a5d Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
…ironment Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/7fb02264-b78f-4248-bd9c-6e74b2f3270d Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
…429e1a9-dbd5-4b36-b891-14c7551bd9c5' into copilot/add-windows-native-executables # Conflicts: # .github/workflows/build.yml Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Added git status command to the build process.
Member
|
@copilot merge copilot/add-windows-native-executables |
…ub.com/OpenIdentityPlatform/OpenDJ into copilot/fix-dostopapplication-infinite-loop Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Contributor
Author
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.
nTries--;decrement indoStopApplication()while loop inservice.cservice.ccopilot/add-windows-native-executables(Windows native executables build steps in.github/workflows/build.yml)Original prompt
Bug
In
opendj-server-legacy/src/build-tools/windows/service.c, thedoStopApplication()function has a critical bug: thenTriescounter is never decremented in the while loop that checks whether the server has stopped. This causes the loop to run infinitely if the server doesn't release its lock file quickly, which leads to the unpredictable start/stop behavior described in issue #72.Root Cause
In
doStopApplication()(line 678), the while loop checksnTries > 0but never decrementsnTries:Compare with the correct implementation in
doStartApplication()(line 607-620) which properly decrements:Fix Required
Add
nTries--;as the first statement inside the while loop indoStopApplication(), right after the opening brace of the while loop on line 679 (between lines 679 and 680), so it matches the pattern used indoStartApplication().The file is:
opendj-server-legacy/src/build-tools/windows/service.cBlobSha:
0f9f6e0fc0d849157a485f6189518dd70858df7fThe fix is a single line addition. Change the while loop (around line 678) from:
to:
This ensures the stop polling loop will eventually time out (after ~23 seconds: 3s initial sleep + 10 tries × 2s) rather than hanging indefinitely, which fixes the Windows service stop behavior described in issue #72.
Refs: #72
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: проанализируй
Assistant:
Let me analyze this issue and look at the relevant code in the repository.
Assistant: Вот детальный анализ issue #72 — "Start-DS and Stop-DS have unpredictable behaviours" на основе исходного кода.
🔍 Корневые причины проблемы
Проанализировав код, я выявил несколько ключевых багов и архитектурных проблем:
1. 🐛 Баг:
nTriesне декрементируется вdoStopApplication()(service.c)Это критический баг. В функции
doStopApplication()в файлеservice.c:Проблема: Переменная
nTriesникогда не уменьшается (nTries--отсутствует). Сравните с аналогичным циклом вdoStartApplication(), гдеnTries--присутствует:Следствие: Если сервер не останавливается быстро, цикл в
doStopApplication()становится бесконечным (покаisServerRunningне вернёт ошибку), что может привести к зависанию Windows-сервиса на этапеSTOP_PENDING.2. 🐛 Ложный exit code 0 у
stop-ds.batВ
stop-ds.batпри пути:stopAsWindowsService:Проблема: После вызова
StopWindowsServiceскрипт безусловно переходит к:end, не проверяя%errorlevel%. Это значит, что даже еслиStopWindowsServiceвернул ошибку, батник завершится с кодом 0. Пользователь видит успешное завершение, хотя сервер ещё работает.3. 🐛
StopWindowsService.javaсчитает ...This pull request was created from Copilot chat.