From 3c197bad3090e446c27b9d9e7a8de44fa81bbb52 Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Mon, 20 Jun 2016 13:50:59 -0700 Subject: [PATCH] Ensure locking of `Server`'s `remoteConsuls`. --- consul/rpc.go | 6 ++++++ consul/server.go | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/consul/rpc.go b/consul/rpc.go index ea054cdb5d..9851c3064e 100644 --- a/consul/rpc.go +++ b/consul/rpc.go @@ -260,7 +260,13 @@ func (s *Server) globalRPC(method string, args interface{}, respCh := make(chan interface{}) // Make a new request into each datacenter + s.remoteLock.RLock() + dcs := make([]string, 0, len(s.remoteConsuls)) for dc, _ := range s.remoteConsuls { + dcs = append(dcs, dc) + } + s.remoteLock.RUnlock() + for _, dc := range dcs { go func(dc string) { rr := reply.New() if err := s.forwardDC(method, dc, args, &rr); err != nil { diff --git a/consul/server.go b/consul/server.go index 2f77ca23cd..2bc8ad7061 100644 --- a/consul/server.go +++ b/consul/server.go @@ -731,13 +731,16 @@ func (s *Server) Stats() map[string]map[string]string { toString := func(v uint64) string { return strconv.FormatUint(v, 10) } + s.remoteLock.RLock() + numKnownDCs := len(s.remoteConsuls) + s.remoteLock.RUnlock() stats := map[string]map[string]string{ "consul": map[string]string{ "server": "true", "leader": fmt.Sprintf("%v", s.IsLeader()), "leader_addr": s.raft.Leader(), "bootstrap": fmt.Sprintf("%v", s.config.Bootstrap), - "known_datacenters": toString(uint64(len(s.remoteConsuls))), + "known_datacenters": toString(uint64(numKnownDCs)), }, "raft": s.raft.Stats(), "serf_lan": s.serfLAN.Stats(),