From 2e0d7097d10effbb4b4b7224e7b74db578c4f0c6 Mon Sep 17 00:00:00 2001 From: Max Ma Date: Mon, 23 Sep 2024 16:17:47 +0200 Subject: [PATCH] add mutex for set peers --- functions/daemon.go | 2 +- wireguard/wireguard.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/functions/daemon.go b/functions/daemon.go index 29aab710..bc086a6a 100644 --- a/functions/daemon.go +++ b/functions/daemon.go @@ -215,7 +215,7 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc { } } slog.Info("configuring netmaker wireguard interface") - pullresp, _, _, pullErr := Pull(true) + pullresp, _, _, pullErr := Pull(false) if pullErr != nil { slog.Error("fail to pull config from server", "error", pullErr.Error()) } diff --git a/wireguard/wireguard.go b/wireguard/wireguard.go index 110b0a7a..3b371661 100644 --- a/wireguard/wireguard.go +++ b/wireguard/wireguard.go @@ -41,7 +41,8 @@ func ShouldReplace(incomingPeers []wgtypes.PeerConfig) bool { // SetPeers - sets peers on netmaker WireGuard interface func SetPeers(replace bool) error { - + wgMutex.Lock() + defer wgMutex.Unlock() peers := config.Netclient().HostPeers for i := range peers { peer := peers[i] @@ -70,6 +71,8 @@ func SetPeers(replace bool) error { // temporarily making public func to pass staticchecks // this function will be required in future when update node on server is refactored func UpdatePeer(p *wgtypes.PeerConfig) error { + wgMutex.Lock() + defer wgMutex.Unlock() config := wgtypes.Config{ Peers: []wgtypes.PeerConfig{*p}, ReplacePeers: false,