From efbaf2cc2d48cb41f6813887b298df6b2aa1a89f Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Fri, 30 Mar 2018 10:18:14 -0700 Subject: [PATCH] drain: fix cli blocking when allocs already stopped --- api/nodes.go | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/api/nodes.go b/api/nodes.go index 77e61624a..4633efe88 100644 --- a/api/nodes.go +++ b/api/nodes.go @@ -215,27 +215,11 @@ func (n *Nodes) monitorDrainNode(ctx context.Context, nodeID string, index uint6 func (n *Nodes) monitorDrainAllocs(ctx context.Context, nodeID string, ignoreSys bool, allocCh, errCh chan<- string) { defer close(allocCh) - // Build initial alloc state q := QueryOptions{AllowStale: true} - allocs, meta, err := n.Allocations(nodeID, &q) - if err != nil { - msg := fmt.Sprintf("Error monitoring allocations: %v", err) - select { - case errCh <- msg: - case <-ctx.Done(): - } - return - } - - initial := make(map[string]*Allocation, len(allocs)) - for _, a := range allocs { - initial[a.ID] = a - } + initial := make(map[string]*Allocation, 4) for { - q.WaitIndex = meta.LastIndex - - allocs, meta, err = n.Allocations(nodeID, &q) + allocs, meta, err := n.Allocations(nodeID, &q) if err != nil { msg := fmt.Sprintf("Error monitoring allocations: %v", err) select { @@ -245,6 +229,8 @@ func (n *Nodes) monitorDrainAllocs(ctx context.Context, nodeID string, ignoreSys return } + q.WaitIndex = meta.LastIndex + runningAllocs := 0 for _, a := range allocs { // Get previous version of alloc