From f67217297c462d08c799a2da5b8c0ff908568ca1 Mon Sep 17 00:00:00 2001 From: Diptanu Choudhury Date: Tue, 29 Nov 2016 07:37:43 -0800 Subject: [PATCH] Ensuring allocs are not added multiple times to blocking queue --- client/client.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/client/client.go b/client/client.go index 9a4e47d1b..329c21c20 100644 --- a/client/client.go +++ b/client/client.go @@ -1370,22 +1370,32 @@ func (c *Client) runAllocs(update *allocUpdates) { for _, add := range diff.added { // If the allocation is chained and the previous allocation hasn't // terminated yet, then add the alloc to the blocked queue. + c.blockedAllocsLock.Lock() ar, ok := c.getAllocRunners()[add.PreviousAllocation] if ok && !ar.Alloc().Terminated() { - c.logger.Printf("[DEBUG] client: added alloc %q to blocked queue", add.ID) - c.blockedAllocsLock.Lock() - c.blockedAllocations[add.PreviousAllocation] = add + // Check if the alloc is already present in the blocked allocations + // map + if _, ok := c.blockedAllocations[add.PreviousAllocation]; !ok { + c.logger.Printf("[DEBUG] client: added alloc %q to blocked queue for previous allocation %q", add.ID, + add.PreviousAllocation) + c.blockedAllocations[add.PreviousAllocation] = add + } c.blockedAllocsLock.Unlock() continue } + c.blockedAllocsLock.Unlock() // This means the allocation has a previous allocation on another node // so we will block for the previous allocation to complete if add.PreviousAllocation != "" && !ok { + // Ensure that we are not blocking for the remote allocation if we + // have already blocked c.migratingAllocsLock.Lock() - c.migratingAllocs[add.ID] = make(chan struct{}) + if _, ok := c.migratingAllocs[add.ID]; !ok { + c.migratingAllocs[add.ID] = make(chan struct{}) + go c.blockForRemoteAlloc(add) + } c.migratingAllocsLock.Unlock() - go c.blockForRemoteAlloc(add) continue }