From 8b097f279d2528bd8475537754ffe698a95399a6 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Tue, 21 Feb 2017 12:39:49 -0800 Subject: [PATCH] tcpproxy: don't use range variable in reactivate goroutine Ends up trying to reactivate only the last endpoint. --- proxy/tcpproxy/userspace.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/proxy/tcpproxy/userspace.go b/proxy/tcpproxy/userspace.go index d8ff11ec548..5de017a70de 100644 --- a/proxy/tcpproxy/userspace.go +++ b/proxy/tcpproxy/userspace.go @@ -147,16 +147,17 @@ func (tp *TCPProxy) runMonitor() { select { case <-time.After(tp.MonitorInterval): tp.mu.Lock() - for _, r := range tp.remotes { - if !r.isActive() { - go func() { - if err := r.tryReactivate(); err != nil { - plog.Warningf("failed to activate endpoint [%s] due to %v (stay inactive for another %v)", r.addr, err, tp.MonitorInterval) - } else { - plog.Printf("activated %s", r.addr) - } - }() + for _, rem := range tp.remotes { + if rem.isActive() { + continue } + go func(r *remote) { + if err := r.tryReactivate(); err != nil { + plog.Warningf("failed to activate endpoint [%s] due to %v (stay inactive for another %v)", r.addr, err, tp.MonitorInterval) + } else { + plog.Printf("activated %s", r.addr) + } + }(rem) } tp.mu.Unlock() case <-tp.donec: