From 675457873aebe550d151582978ddc63bdc5050d9 Mon Sep 17 00:00:00 2001 From: Cameron Sparr Date: Thu, 2 Jun 2016 11:22:07 +0100 Subject: [PATCH] haproxy input: fix potential race condition --- plugins/inputs/haproxy/haproxy.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/inputs/haproxy/haproxy.go b/plugins/inputs/haproxy/haproxy.go index d3f3d0696..396e3c934 100644 --- a/plugins/inputs/haproxy/haproxy.go +++ b/plugins/inputs/haproxy/haproxy.go @@ -6,6 +6,7 @@ import ( "github.com/influxdata/telegraf" "github.com/influxdata/telegraf/plugins/inputs" "io" + "log" "net" "net/http" "net/url" @@ -113,20 +114,18 @@ func (g *haproxy) Gather(acc telegraf.Accumulator) error { } var wg sync.WaitGroup - - var outerr error - - for _, serv := range g.Servers { + for _, server := range g.Servers { wg.Add(1) go func(serv string) { defer wg.Done() - outerr = g.gatherServer(serv, acc) - }(serv) + if err := g.gatherServer(serv, acc); err != nil { + log.Printf("HAProxy error gathering server: %s, %s", serv, err) + } + }(server) } wg.Wait() - - return outerr + return nil } func (g *haproxy) gatherServerSocket(addr string, acc telegraf.Accumulator) error {