Skip to content

Commit

Permalink
fix: avoid concurrent map writes (#3729)
Browse files Browse the repository at this point in the history
Signed-off-by: fengxsong <fengxsong@outlook.com>
  • Loading branch information
fengxsong committed Aug 22, 2023
1 parent cd47600 commit cf4242d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/env/env.go
Expand Up @@ -21,6 +21,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"github.com/labring/sealos/pkg/template"
"github.com/labring/sealos/pkg/types/v1beta1"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cf4242d

Please sign in to comment.