From 7f78d1748ededc997d7116e5e5da1fef47d33bbe Mon Sep 17 00:00:00 2001 From: sealos-ci-robot <109538726+sealos-ci-robot@users.noreply.github.com> Date: Tue, 22 Aug 2023 12:31:40 +0800 Subject: [PATCH] fix: avoid concurrent map writes (#3729) (#3730) Signed-off-by: fengxsong Co-authored-by: fengxsong --- pkg/env/env.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/env/env.go b/pkg/env/env.go index 1fab00b20da..722a7e4e742 100644 --- a/pkg/env/env.go +++ b/pkg/env/env.go @@ -21,6 +21,7 @@ import ( "os" "path/filepath" "strings" + "sync" "github.com/labring/sealos/pkg/template" "github.com/labring/sealos/pkg/types/v1beta1" @@ -47,6 +48,7 @@ type Interface interface { type processor struct { *v1beta1.Cluster cache map[string]map[string]string + mu sync.Mutex } func NewEnvProcessor(cluster *v1beta1.Cluster) Interface { @@ -118,6 +120,8 @@ func (p *processor) getHostEnvInCache(hostIP string) map[string]string { if v, ok := p.cache[hostIP]; ok { return v } + p.mu.Lock() + defer p.mu.Unlock() v := p.getHostEnv(hostIP) p.cache[hostIP] = v return v