Skip to content

Commit

Permalink
Fix waitgroup deadlock if url is incorrect in apache input (#4176)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkady-emelyanov authored and leodido committed May 22, 2018
1 parent 25c3ed0 commit bd8191e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions plugins/inputs/apache/apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
}
Expand All @@ -72,15 +74,14 @@ 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 {
acc.AddError(fmt.Errorf("Unable to parse address '%s': %s", u, err))
continue
}

wg.Add(1)
go func(addr *url.URL) {
defer wg.Done()
acc.AddError(n.gatherUrl(addr, acc))
Expand Down

0 comments on commit bd8191e

Please sign in to comment.