From e5bd6a7ed35a4d5ed75023719814541423affc48 Mon Sep 17 00:00:00 2001 From: StoneHuang <676580030@qq.com> Date: Tue, 24 Mar 2020 23:43:30 +0800 Subject: [PATCH] fix(controller): Updates GetTaskAncestry to skip visited nod. Fixes #1907 (#1908) --- workflow/common/ancestry.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/workflow/common/ancestry.go b/workflow/common/ancestry.go index a2eb10615488..fe858f7e9531 100644 --- a/workflow/common/ancestry.go +++ b/workflow/common/ancestry.go @@ -18,19 +18,23 @@ func GetTaskAncestry(ctx Context, taskName string, tasks []wfv1.DAGTask) []strin for _, task := range tasks { taskByName[task.Name] = task } - + visitedFlag := make(map[string]bool) visited := make(map[string]time.Time) var getAncestry func(s string) getAncestry = func(currTask string) { - task := taskByName[currTask] - for _, depTask := range task.Dependencies { - getAncestry(depTask) - } - if currTask != taskName { - if _, ok := visited[currTask]; !ok { - visited[currTask] = getTimeFinished(ctx, currTask) + if !visitedFlag[currTask] { + task := taskByName[currTask] + for _, depTask := range task.Dependencies { + getAncestry(depTask) } + if currTask != taskName { + if _, ok := visited[currTask]; !ok { + visited[currTask] = getTimeFinished(ctx, currTask) + } + } + visitedFlag[currTask] = true } + } getAncestry(taskName)