Fix waitgroup deadlock if url is incorrect in apache input (#4176)
(cherry picked from commit 7f46aafcd6
)
This commit is contained in:
parent
066e048b5f
commit
e106bac61c
|
@ -63,6 +63,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"}
|
||||||
}
|
}
|
||||||
|
@ -78,8 +80,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 {
|
||||||
|
@ -87,6 +87,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))
|
||||||
|
|
Loading…
Reference in New Issue