From cc9648c95768ba12bb098c551d0c8abb8b49177d Mon Sep 17 00:00:00 2001 From: Wei Wei Date: Tue, 5 Dec 2017 11:35:32 +0800 Subject: [PATCH] fix globalRPC goroutine leak Signed-off-by: Wei Wei --- agent/consul/rpc.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/agent/consul/rpc.go b/agent/consul/rpc.go index 927fe4f1af..678b805140 100644 --- a/agent/consul/rpc.go +++ b/agent/consul/rpc.go @@ -307,11 +307,13 @@ func (s *Server) forwardDC(method, dc string, args interface{}, reply interface{ func (s *Server) globalRPC(method string, args interface{}, reply structs.CompoundResponse) error { - errorCh := make(chan error) - respCh := make(chan interface{}) - // Make a new request into each datacenter dcs := s.router.GetDatacenters() + + replies, total := 0, len(dcs) + errorCh := make(chan error, total) + respCh := make(chan interface{}, total) + for _, dc := range dcs { go func(dc string) { rr := reply.New() @@ -323,7 +325,6 @@ func (s *Server) globalRPC(method string, args interface{}, }(dc) } - replies, total := 0, len(dcs) for replies < total { select { case err := <-errorCh: