Browse Source

added mutex lock for conf writes

0xdcarns 3 years ago
parent
commit
5a3b6141bd
1 changed files with 8 additions and 1 deletions
  1. 8 1
      netclient/config/config.go

+ 8 - 1
netclient/config/config.go

@@ -10,6 +10,7 @@ import (
 	"fmt"
 	"log"
 	"os"
+	"sync"
 
 	"github.com/gravitl/netmaker/logger"
 	"github.com/gravitl/netmaker/models"
@@ -18,6 +19,10 @@ import (
 	"gopkg.in/yaml.v3"
 )
 
+var (
+	configLock sync.Mutex
+)
+
 // ClientConfig - struct for dealing with client configuration
 type ClientConfig struct {
 	Server          ServerConfig   `yaml:"server"`
@@ -52,6 +57,8 @@ type RegisterResponse struct {
 
 // Write - writes the config of a client to disk
 func Write(config *ClientConfig, network string) error {
+	configLock.Lock()
+	defer configLock.Unlock()
 	if network == "" {
 		err := errors.New("no network provided - exiting")
 		return err
@@ -140,7 +147,7 @@ func ModConfig(node *models.Node) error {
 	return Write(&modconfig, network)
 }
 
-// ModConfig - overwrites the node inside client config on disk
+// SaveBackup - saves a backup file of a given network
 func SaveBackup(network string) error {
 
 	var configPath = ncutils.GetNetclientPathSpecific() + "netconfig-" + network