From 2787b376effed62c6a0c30c25150099c37d76f0b Mon Sep 17 00:00:00 2001 From: Pier-Hugues Pellerin Date: Mon, 1 Aug 2022 15:43:59 -0400 Subject: [PATCH] Fix a panic with wg passed to the composable object In the code to retrieve the variables from the configuration files we need to pass a execution callback, this callback will be called in a goroutine. This callback can be executed multiple time until the composable renderer is stopped. There were a problem in the code that made the callback called multiple time and it made the waitgroup internal counter to do to a negative values. This commit change the behavior, it start the composable renderer give it a callback when the callback receives the variables it will stop the composable's Run method using the context. This ensure that the callback will be called a single time and that the variables are correctly retrieved. Fixes: #806 --- internal/pkg/agent/install/uninstall.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/pkg/agent/install/uninstall.go b/internal/pkg/agent/install/uninstall.go index 87ff47ae169..2a09698716f 100644 --- a/internal/pkg/agent/install/uninstall.go +++ b/internal/pkg/agent/install/uninstall.go @@ -235,9 +235,15 @@ func applyDynamics(ctx context.Context, log *logger.Logger, cfg *config.Config) varsArray := make([]*transpiler.Vars, 0) var wg sync.WaitGroup wg.Add(1) + + ctx, cancel := context.WithCancel(ctx) + + // The composable system will continuously run, we are only interested in the first run on of the + // renderer to collect the variables we should stop the execution. varsCallback := func(vv []*transpiler.Vars) { varsArray = vv wg.Done() + cancel() } ctrl, err := composable.New(log, cfg)