diff --git a/.changelog/17971.txt b/.changelog/17971.txt new file mode 100644 index 000000000..26ac94bbe --- /dev/null +++ b/.changelog/17971.txt @@ -0,0 +1,3 @@ +```release-note:bug +client: Fixed a bug where the state of poststop tasks could be corrupted by client gc +``` diff --git a/client/allocrunner/alloc_runner.go b/client/allocrunner/alloc_runner.go index 84c1466dd..19474faae 100644 --- a/client/allocrunner/alloc_runner.go +++ b/client/allocrunner/alloc_runner.go @@ -734,6 +734,19 @@ func (ar *allocRunner) killTasks() map[string]*structs.TaskState { } wg.Wait() + // Perform no action on post stop tasks, but retain their states if they exist. This + // commonly happens at the time of alloc GC from the client node. + for name, tr := range ar.tasks { + if !tr.IsPoststopTask() { + continue + } + + state := tr.TaskState() + if state != nil { + states[name] = state + } + } + return states }