Browse Source

Merge pull request #7361 from heyitsanthony/fix-gateway-goroutine

tcpproxy: don't use range variable in reactivate goroutine
Anthony Romano 8 years ago
parent
commit
25403970f5
1 changed files with 10 additions and 9 deletions
  1. 10 9
      proxy/tcpproxy/userspace.go

+ 10 - 9
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: