Skip to content

Commit

Permalink
Fix a panic during plan evaluation
Browse files Browse the repository at this point in the history
This PR fixes a potential source of a panic while evaluating a plan with
all_at_once set to true with partial failures.

Potentially fixes #2531
  • Loading branch information
dadgar committed Apr 10, 2017
1 parent 0d2e99b commit 1cfae1a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nomad/plan_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nomad
import (
"fmt"
"runtime"
"sync"
"time"

"github.com/armon/go-metrics"
Expand Down Expand Up @@ -196,6 +197,7 @@ func evaluatePlan(pool *EvaluatePool, snap *state.StateSnapshot, plan *structs.P
defer metrics.MeasureSince([]string{"nomad", "plan", "evaluate"}, time.Now())

// Create a result holder for the plan
var resLock sync.Mutex
result := &structs.PlanResult{
NodeUpdate: make(map[string][]*structs.Allocation),
NodeAllocation: make(map[string][]*structs.Allocation),
Expand Down Expand Up @@ -224,6 +226,9 @@ func evaluatePlan(pool *EvaluatePool, snap *state.StateSnapshot, plan *structs.P

// handleResult is used to process the result of evaluateNodePlan
handleResult := func(nodeID string, fit bool, err error) (cancel bool) {
resLock.Lock()
defer resLock.Unlock()

// Evaluate the plan for this node
if err != nil {
mErr.Errors = append(mErr.Errors, err)
Expand All @@ -245,6 +250,11 @@ func evaluatePlan(pool *EvaluatePool, snap *state.StateSnapshot, plan *structs.P
return
}

// Check to see if the plan has been cancelled
if result.NodeAllocation == nil || result.NodeUpdate == nil {
return
}

// Add this to the plan result
if nodeUpdate := plan.NodeUpdate[nodeID]; len(nodeUpdate) > 0 {
result.NodeUpdate[nodeID] = nodeUpdate
Expand Down

0 comments on commit 1cfae1a

Please sign in to comment.