From b9a388f5df546c63c554491b49550fd9bc5262bc Mon Sep 17 00:00:00 2001 From: stswidwinski Date: Fri, 21 Jul 2023 13:55:00 -0400 Subject: [PATCH] Retain task states for post stop tasks at the time of node GC (#18005) * Retain task states for post stop tasks at the time of node GC --- .changelog/17971.txt | 3 +++ client/allocrunner/alloc_runner.go | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .changelog/17971.txt 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 }