From b954e565cc1f84d811c4476f37a1d11048a9665e Mon Sep 17 00:00:00 2001 From: JC <31185072+jhychan@users.noreply.github.com> Date: Thu, 2 Dec 2021 22:32:19 +0000 Subject: [PATCH] fix: windows service - graceful shutdown of telegraf (#9616) --- cmd/telegraf/telegraf_windows.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/telegraf/telegraf_windows.go b/cmd/telegraf/telegraf_windows.go index 38222f2d0871d..8e2a6be1925d5 100644 --- a/cmd/telegraf/telegraf_windows.go +++ b/cmd/telegraf/telegraf_windows.go @@ -45,9 +45,12 @@ func (p *program) run() { p.inputFilters, p.outputFilters, ) + close(stop) } func (p *program) Stop(s service.Service) error { - close(stop) + var empty struct{} + stop <- empty // signal reloadLoop to finish (context cancel) + <-stop // wait for reloadLoop to finish and close channel return nil }