Fix Windows zombie process on shutdown - #2248
Draft
gargritik121-a11y wants to merge 3 commits into
Draft
Conversation
When Stop() is called, it now waits for reloadLoop to finish via a done channel with a 15-second timeout. If goroutines are stuck in blocking syscalls (e.g., PdhCollectQueryData on Windows when PDH is broken), Go cannot interrupt them. Previously, Stop() returned immediately, telling Windows SCM the service was stopped while the process remained alive as an unkillable zombie. This fix ensures: - Normal shutdown: Stop() waits for done channel, returns cleanly - Stuck shutdown: After 15s timeout, os.Exit(1) forces process exit The 15s timeout is under Windows default WaitToKillServiceTimeout (20s). Fixes: V2288965817 (ES2 escalation - DB Systel GmbH)
Contributor
Binary Size Reportlinux/amd64
linux/arm64
windows/amd64
Investigating size changesUse go-size-analyzer to compare binaries: GOEXPERIMENT=jsonv2 go install github.com/Zxilly/go-size-analyzer/cmd/gsa@latest
gsa diff --old <baseline-binary> --new <new-binary> |
os.Exit() tries to clean up Go runtime (run finalizers, stop goroutines) which blocks when threads are suspended. syscall.Exit() calls ExitProcess directly without cleanup, ensuring the process actually terminates. Discovered during manual repro testing on Windows Server 2022.
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.
Problem
When Stop() is called on Windows, it returns immediately without waiting for goroutines. If a goroutine is blocked in a syscall (e.g., PdhCollectQueryData when PDH is broken), the process remains alive as an unkillable zombie.
Customer impact: Cannot restart agent, cannot kill process, only reboot recovers.
Solution
Add a done channel that reloadLoop closes on exit. Stop() waits for it with 15s timeout, then os.Exit(1) if stuck.
Testing