From 030e650e7850d6ab8890fb2ab22c7562e91e2027 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Mon, 2 Jul 2018 16:05:38 -0400 Subject: [PATCH 1/2] scheduler: fix nil pointer exception --- scheduler/generic_sched.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index e0ad0074c..c4b6d7c46 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -597,7 +597,7 @@ func (s *GenericScheduler) findPreferredNode(place placementResult) (node *struc var preferredNode *structs.Node ws := memdb.NewWatchSet() preferredNode, err = s.state.NodeByID(ws, prev.NodeID) - if preferredNode.Ready() { + if preferredNode != nil && preferredNode.Ready() { node = preferredNode } } From 5f6def5b0438e0b93fed59744f3e5a063b445f99 Mon Sep 17 00:00:00 2001 From: Nick Ethier Date: Thu, 5 Jul 2018 11:00:03 -0400 Subject: [PATCH 2/2] scheduler: better error handling --- scheduler/generic_sched.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index c4b6d7c46..61a5bf594 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -592,14 +592,18 @@ func updateRescheduleTracker(alloc *structs.Allocation, prev *structs.Allocation } // findPreferredNode finds the preferred node for an allocation -func (s *GenericScheduler) findPreferredNode(place placementResult) (node *structs.Node, err error) { +func (s *GenericScheduler) findPreferredNode(place placementResult) (*structs.Node, error) { if prev := place.PreviousAllocation(); prev != nil && place.TaskGroup().EphemeralDisk.Sticky == true { var preferredNode *structs.Node ws := memdb.NewWatchSet() preferredNode, err = s.state.NodeByID(ws, prev.NodeID) + if err != nil { + return nil, err + } + if preferredNode != nil && preferredNode.Ready() { - node = preferredNode + return preferredNode, nil } } - return + return nil, nil }