From 5a3581d4625fd5bc08b292b8167e4edcc98e5d52 Mon Sep 17 00:00:00 2001 From: Horst Gutmann Date: Mon, 7 Oct 2024 08:58:35 +0200 Subject: [PATCH] fix: prevent concurrent writes in `env list` command (#1182) --- pkg/tanka/find.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/tanka/find.go b/pkg/tanka/find.go index d34362653..1f7bbf591 100644 --- a/pkg/tanka/find.go +++ b/pkg/tanka/find.go @@ -127,9 +127,13 @@ func findEnvsFromJsonnetFiles(jsonnetFiles []string, opts FindOpts) ([]*v1alpha1 for i := 0; i < opts.Parallelism; i++ { go func() { + // We need to create a copy of the opts for each goroutine because + // the content may be modified down the line: + jsonnetOpts := opts.JsonnetOpts.Clone() + for jsonnetFile := range jsonnetFilesChan { // try if this has envs - list, err := List(jsonnetFile, Opts{JsonnetOpts: opts.JsonnetOpts}) + list, err := List(jsonnetFile, Opts{JsonnetOpts: jsonnetOpts}) if err != nil && // expected when looking for environments !errors.As(err, &jpath.ErrorNoBase{}) &&