From d6580a1c4aa5cd0f7e499c34f96439ed0994c6e5 Mon Sep 17 00:00:00 2001 From: Matthew Fisher Date: Fri, 11 Oct 2019 10:59:36 -0700 Subject: [PATCH] fix(kube): fix race condition .Get() calls perform() on a list of infos, populating two shared maps. perform() now concurrently calls the ResourceActorFunc concurrently based on GVK, causing a data race condition in .Get() This fixes that condition by locking the function to ensure these functions run serially for Helm 2 to fix the data race condition. This has since been optimized in Helm 3 so it's no longer an issue. Signed-off-by: Matthew Fisher --- pkg/kube/client.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 0d2ca20e6..79f7eb4bf 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -218,6 +218,8 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) { // Since we don't know what order the objects come in, let's group them by the types and then sort them, so // that when we print them, they come out looking good (headers apply to subgroups, etc.). objs := make(map[string](map[string]runtime.Object)) + mux := &sync.Mutex{} + infos, err := c.BuildUnstructured(namespace, reader) if err != nil { return "", err @@ -227,6 +229,8 @@ func (c *Client) Get(namespace string, reader io.Reader) (string, error) { missing := []string{} err = perform(infos, func(info *resource.Info) error { + mux.Lock() + defer mux.Unlock() c.Log("Doing get for %s: %q", info.Mapping.GroupVersionKind.Kind, info.Name) if err := info.Get(); err != nil { c.Log("WARNING: Failed Get for resource %q: %s", info.Name, err)