Skip to content

Commit

Permalink
Ensure lifecycleConfig is not nil before dereferencing 'Hook'.
Browse files Browse the repository at this point in the history
  • Loading branch information
beautifulentropy committed Jan 27, 2022
1 parent 7371f4f commit 300b061
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions client/allochealth/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (t *Tracker) watchTaskEvents() {
// Detect if the alloc is unhealthy or if all tasks have started yet
latestStartTime := time.Time{}
for taskName, state := range alloc.TaskStates {
if t.lifecycleTasks[taskName] != nil {
if t.lifecycleTasks != nil && t.lifecycleTasks[taskName] != nil {
// If the task is a poststop task we do not want to evaluate it
// since it will remain pending until the main task has finished or
// exited.
Expand All @@ -302,12 +302,12 @@ func (t *Tracker) watchTaskEvents() {
continue
}
}
}

// One of the tasks has failed so we can exit watching
if state.Failed || (!state.FinishedAt.IsZero() && t.lifecycleTasks[taskName].Hook != structs.TaskLifecycleHookPrestart) {
t.setTaskHealth(false, true)
return
// One of the tasks has failed so we can exit watching
if state.Failed || (!state.FinishedAt.IsZero() && t.lifecycleTasks[taskName].Hook != structs.TaskLifecycleHookPrestart) {
t.setTaskHealth(false, true)
return
}
}

if state.State == structs.TaskStatePending {
Expand Down

0 comments on commit 300b061

Please sign in to comment.