Skip to content

Fix Windows zombie process on shutdown - #2248

Draft
gargritik121-a11y wants to merge 3 commits into
mainfrom
fix-windows-zombie-shutdown
Draft

Fix Windows zombie process on shutdown#2248
gargritik121-a11y wants to merge 3 commits into
mainfrom
fix-windows-zombie-shutdown

Conversation

@gargritik121-a11y

@gargritik121-a11y gargritik121-a11y commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

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

  • Build passes
  • Unit test for happy path added
  • Manual Windows test pending

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)
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Binary Size Report

linux/amd64

Binary PR vs main (9884add) vs v1.300072.0
amazon-cloudwatch-agent 193.3 MB +0 B +0 B
amazon-cloudwatch-agent-config-wizard 2.0 MB +0 B +0 B
config-downloader 2.0 MB +0 B +0 B
config-translator 2.0 MB +0 B +0 B
start-amazon-cloudwatch-agent 2.5 MB +0 B +0 B
workload-discovery 3.0 MB +0 B +0 B
Total 204.9 MB +0 B +0 B
linux/amd64 amazon-cloudwatch-agent (last 9 main commits + this PR)

 193 ┤                                        
     ┤                ███ ███ ███ ███ ███ ███ 
     ┤                ███ ███ ███ ███ ███ ███ 
     ┤                ███ ███ ███ ███ ███ ███ 
     ┤            ▄▄▄ ███ ███ ███ ███ ███ ███ 
     ┤            ███ ███ ███ ███ ███ ███ ███ 
     ┤            ███ ███ ███ ███ ███ ███ ███ 
     ┤            ███ ███ ███ ███ ███ ███ ███ 
 193 ┤▄▄▄ ▄▄▄ ▄▄▄ ███ ███ ███ ███ ███ ███ ███ 
 MB  └────────────────────────────────────────
      ab55b8d                     v1.30007PR0
linux/arm64
Binary PR vs main (9884add) vs v1.300072.0
amazon-cloudwatch-agent 177.1 MB +0 B +0 B
amazon-cloudwatch-agent-config-wizard 2.0 MB +0 B +0 B
config-downloader 2.0 MB +0 B +0 B
config-translator 2.0 MB +0 B +0 B
start-amazon-cloudwatch-agent 2.4 MB +0 B +0 B
workload-discovery 2.9 MB +0 B +0 B
Total 188.4 MB +0 B +0 B
windows/amd64
Binary PR vs main (9884add) vs v1.300072.0
amazon-cloudwatch-agent.exe 196.1 MB ${\color{red}▲}$ +7.7 KB (+0.0%) ${\color{red}▲}$ +7.7 KB (+0.0%)
amazon-cloudwatch-agent-config-wizard.exe 2.1 MB +0 B +0 B
config-downloader.exe 2.1 MB +0 B +0 B
config-translator.exe 2.1 MB +0 B +0 B
start-amazon-cloudwatch-agent.exe 2.3 MB +0 B +0 B
workload-discovery.exe 2.9 MB +0 B +0 B
Total 207.7 MB ${\color{red}▲}$ +7.7 KB (+0.0%) ${\color{red}▲}$ +7.7 KB (+0.0%)
Investigating size changes

Use 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant