From 167f2f0937ca00ffdc9f2ea833dbc4806bf5bea6 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Wed, 23 Mar 2016 17:54:32 -0700 Subject: [PATCH] Locking on alloc runners before syncing with consul --- client/client.go | 7 +++++++ client/consul/sync.go | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/client/client.go b/client/client.go index eb044a2bc..9f303386f 100644 --- a/client/client.go +++ b/client/client.go @@ -1185,7 +1185,14 @@ func (c *Client) syncConsul() { select { case <-sync: var runningTasks []*structs.Task + // Get the existing allocs + c.allocLock.RLock() + allocs := make([]*AllocRunner, 0, len(c.allocs)) for _, ar := range c.allocs { + allocs = append(allocs, ar) + } + c.allocLock.RUnlock() + for _, ar := range allocs { for taskName, taskState := range ar.taskStates { if taskState.State == structs.TaskStateRunning { if tr, ok := ar.tasks[taskName]; ok { diff --git a/client/consul/sync.go b/client/consul/sync.go index a9fcdc102..6675e85ad 100644 --- a/client/consul/sync.go +++ b/client/consul/sync.go @@ -314,7 +314,6 @@ func (c *ConsulService) performSync() error { // with nomad- func (c *ConsulService) filterConsulServices(srvcs map[string]*consul.AgentService) map[string]*consul.AgentService { nomadServices := make(map[string]*consul.AgentService) - delete(srvcs, "consul") for _, srv := range srvcs { if strings.HasPrefix(srv.ID, structs.NomadConsulPrefix) { nomadServices[srv.ID] = srv