From e39671f6970b6ed0b688aa76bee96ffcf670745f Mon Sep 17 00:00:00 2001 From: j Date: Wed, 11 Aug 2021 23:05:39 +0100 Subject: [PATCH] Wait for reloadLoop goroutine to finish before allowing main goroutine to end --- 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..67cb34f88b5e1 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 channel to close return nil }