Fix waitgroup deadlock if url is incorrect in apache input (#4176)

(cherry picked from commit 7f46aafcd6)
This commit is contained in:
Arkady Emelyanov 2018-05-21 20:43:02 +03:00 committed by Daniel Nelson
parent 066e048b5f
commit e106bac61c
No known key found for this signature in database
GPG Key ID: CAAD59C9444F6155
1 changed files with 3 additions and 2 deletions

View File

@ -63,6 +63,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"}
}
@ -78,8 +80,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 {
@ -87,6 +87,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))