From 1acbf1daf962eccb0c0f35e9e5330c2b27ef4d08 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 e0ad0074cd9..c4b6d7c46da 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 3e7d4302a6ca8c346d42873a46a6b8dc1f5636df 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 c4b6d7c46da..61a5bf59479 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 }