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

This commit is contained in:
Arkady Emelyanov 2018-05-21 20:43:02 +03:00 committed by Daniel Nelson
parent 3072b5a493
commit 7f46aafcd6
1 changed files with 3 additions and 2 deletions

View File

@ -57,6 +57,8 @@ func (n *Apache) Description() string {
} }
func (n *Apache) Gather(acc telegraf.Accumulator) error { func (n *Apache) Gather(acc telegraf.Accumulator) error {
var wg sync.WaitGroup
if len(n.Urls) == 0 { if len(n.Urls) == 0 {
n.Urls = []string{"http://localhost/server-status?auto"} n.Urls = []string{"http://localhost/server-status?auto"}
} }
@ -72,8 +74,6 @@ func (n *Apache) Gather(acc telegraf.Accumulator) error {
n.client = client n.client = client
} }
var wg sync.WaitGroup
wg.Add(len(n.Urls))
for _, u := range n.Urls { for _, u := range n.Urls {
addr, err := url.Parse(u) addr, err := url.Parse(u)
if err != nil { if err != nil {
@ -81,6 +81,7 @@ func (n *Apache) Gather(acc telegraf.Accumulator) error {
continue continue
} }
wg.Add(1)
go func(addr *url.URL) { go func(addr *url.URL) {
defer wg.Done() defer wg.Done()
acc.AddError(n.gatherUrl(addr, acc)) acc.AddError(n.gatherUrl(addr, acc))