1
0
mirror of https://github.com/rancher/rke.git synced 2025-04-28 11:36:27 +00:00

lock to avoid concurrent map writes

This commit is contained in:
kinarashah 2020-02-28 14:11:09 -08:00
parent 02bab32a40
commit 18f42726b0

View File

@ -7,6 +7,7 @@ import (
"net/http" "net/http"
"os" "os"
"strings" "strings"
"sync"
"time" "time"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -36,9 +37,12 @@ var (
c = http.Client{ c = http.Client{
Timeout: time.Second * 30, Timeout: time.Second * 30,
} }
kdmMutex = sync.Mutex{}
) )
func InitMetadata(ctx context.Context) error { func InitMetadata(ctx context.Context) error {
kdmMutex.Lock()
defer kdmMutex.Unlock()
data, err := loadData() data, err := loadData()
if err != nil { if err != nil {
return fmt.Errorf("failed to load data.json, error: %v", err) return fmt.Errorf("failed to load data.json, error: %v", err)