From 7f46aafcd625237bddcfa97fff54ca88722b7c5e Mon Sep 17 00:00:00 2001 From: Arkady Emelyanov Date: Mon, 21 May 2018 20:43:02 +0300 Subject: [PATCH] Fix waitgroup deadlock if url is incorrect in apache input (#4176) --- plugins/inputs/apache/apache.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/inputs/apache/apache.go b/plugins/inputs/apache/apache.go index a04d1bbb8..1302e2d59 100644 --- a/plugins/inputs/apache/apache.go +++ b/plugins/inputs/apache/apache.go @@ -57,6 +57,8 @@ func (n *Apache) Description() string { } func (n *Apache) Gather(acc telegraf.Accumulator) error { + var wg sync.WaitGroup + if len(n.Urls) == 0 { n.Urls = []string{"http://localhost/server-status?auto"} } @@ -72,8 +74,6 @@ func (n *Apache) Gather(acc telegraf.Accumulator) error { n.client = client } - var wg sync.WaitGroup - wg.Add(len(n.Urls)) for _, u := range n.Urls { addr, err := url.Parse(u) if err != nil { @@ -81,6 +81,7 @@ func (n *Apache) Gather(acc telegraf.Accumulator) error { continue } + wg.Add(1) go func(addr *url.URL) { defer wg.Done() acc.AddError(n.gatherUrl(addr, acc))