Locking on alloc runners before syncing with consul

This commit is contained in:
Diptanu Choudhury
2016-03-23 17:54:32 -07:00
parent 1f6137aba5
commit 167f2f0937
2 changed files with 7 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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