From c6c174d4373c05989d4f00af36c34b6ffd1436aa Mon Sep 17 00:00:00 2001 From: AtomicFS Date: Fri, 17 Jan 2025 18:31:01 +0100 Subject: [PATCH 1/2] test(cmd): orphaned node break DAG Signed-off-by: AtomicFS --- cmd/firmware-action/recipes/recipes_test.go | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cmd/firmware-action/recipes/recipes_test.go b/cmd/firmware-action/recipes/recipes_test.go index b72b87e1..be17b760 100644 --- a/cmd/firmware-action/recipes/recipes_test.go +++ b/cmd/firmware-action/recipes/recipes_test.go @@ -207,6 +207,43 @@ func TestBuild(t *testing.T) { recursive: false, config: testConfigDependencyHell, }, + { + name: "dependency clusterfuck - middle", + wantErr: nil, + target: "milk", + recursive: false, + config: testConfigDependencyHell, + }, + { + name: "two leaves and one root", + wantErr: nil, + target: "stitch", + recursive: false, + config: Config{ + Edk2: map[string]Edk2Opts{ + "edk2-build-a": {Depends: []string{}}, + "edk2-build-b": {Depends: []string{}}, + }, + FirmwareStitching: map[string]FirmwareStitchingOpts{ + "stitch": {Depends: []string{"edk2-build-a"}}, + }, + }, + }, + { + name: "one root and two leaves", + wantErr: nil, + target: "stitch-a", + recursive: false, + config: Config{ + Edk2: map[string]Edk2Opts{ + "edk2-build": {Depends: []string{}}, + }, + FirmwareStitching: map[string]FirmwareStitchingOpts{ + "stitch-a": {Depends: []string{"edk2-build"}}, + "stitch-b": {Depends: []string{"edk2-build"}}, + }, + }, + }, } const interactive = false From f11c86aac56ff64d0191317e0a8f5085d45a9f2f Mon Sep 17 00:00:00 2001 From: Marvin Drees Date: Fri, 17 Jan 2025 20:25:27 +0100 Subject: [PATCH 2/2] fix: create subgraph when multiple roots present If there is more then one root present in the config we need to create a subgraph that only includes the Descendants of the desired root and omits the rest. If we try to step through the initial dag instead it will create a locking situation that will break execution. Signed-off-by: Marvin Drees --- cmd/firmware-action/recipes/recipes.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/firmware-action/recipes/recipes.go b/cmd/firmware-action/recipes/recipes.go index c61599cc..6a90d22e 100644 --- a/cmd/firmware-action/recipes/recipes.go +++ b/cmd/firmware-action/recipes/recipes.go @@ -106,7 +106,15 @@ func Build( queueMutex.Unlock() return nil, nil } - _, err = dependencyForest.DescendantsFlow(target, nil, flowCallback) + + // Create a subgraph with target as the only root + // Having multiple roots will result in miscalculation inside DescendantsFlow channel size calculation + pruned, rootID, err := dependencyForest.GetDescendantsGraph(target) + if err != nil { + return nil, err + } + + _, err = pruned.DescendantsFlow(rootID, nil, flowCallback) if err != nil { return nil, err }