fix(windows platform): report SERVICE_STOPPED to SCM when startup fails#25810
Open
klondikedragon wants to merge 2 commits into
Open
fix(windows platform): report SERVICE_STOPPED to SCM when startup fails#25810klondikedragon wants to merge 2 commits into
klondikedragon wants to merge 2 commits into
Conversation
When Application::prepare_start fails (for example an invalid configuration), run_service returned without registering a service control handler or reporting any status to the SCM. The service then sits in START_PENDING indefinitely and configured recovery (FailureActions) never runs, because the SCM never observes a failure. Register a handler and report SERVICE_STOPPED with the startup exit code as a service-specific exit code, so the failure is visible to the SCM and to service recovery. (cherry picked from commit 0df4002)
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.
Summary
Fixes #25809.
When Vector runs as a Windows service and startup fails (for example, an invalid configuration),
run_servicereturned without registering a service control handler or reporting any status to the Service Control Manager. The SCM left the service stuck inSTART_PENDINGindefinitely: thevector.exeprocess stays alive, the service isNOT_STOPPABLE(sosc stopcannot clear it), no SCM error event is logged, and configured recovery actions never run. Clearing the state required disabling the service and terminating the process by hand.This PR handles the
Errarm ofApplication::prepare_startinrun_service: register a minimal control handler and reportSERVICE_STOPPEDwith the startup exit code as a service-specific exit code. The SCM then shows the failure (WIN32_EXIT_CODE 1066,SERVICE_EXIT_CODE= Vector's exit code, e.g. 78 for a config error), logs event 7024, and service recovery can act on it. The success path (reportRunning, run, reportStopped) is unchanged.Vector configuration
The bug reproduces with any configuration that fails to load; tested by appending a syntactically invalid line to a previously working config:
How did you test this PR?
Windows 11 x64, Vector registered as a Windows service (
vector), config made invalid as above.Before (stock v0.56.0 release binary): stuck forever, process alive, no events.
After (this branch,
cargo build --release): immediate honest stop.System event log now records the failure:
Service recovery now works. With a recovery ladder configured (
sc.exe failure vector reset= 86400 actions= restart/10000/restart/30000/restart/60000plussc.exe failureflag vector 1, which Windows requires for non-crash failures), the SCM retries per the ladder:After correcting the configuration, the SCM's scheduled restart brought the service back to
RUNNINGwith no operator action (a subsequent manualsc.exe startreturnedFAILED 1056: An instance of the service is already running).Regression check with a valid configuration:
sc.exe startreachesRUNNINGandsc.exe stopreachesSTOPPEDwith exit code 0, repeatedly.Change Type
Is this a breaking change?
Does this PR include user facing changes?
no-changeloglabel to this PR.References
Closes: #25809