Skip to content

Commit

Permalink
Fix a panic with wg passed to the composable object
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ph committed Aug 1, 2022
1 parent fd1a95a commit 2787b37
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2787b37

Please sign in to comment.