diff --git a/pro/controllers/failover.go b/pro/controllers/failover.go index 71a72791f..a4fddad9e 100644 --- a/pro/controllers/failover.go +++ b/pro/controllers/failover.go @@ -219,6 +219,14 @@ func failOverME(w http.ResponseWriter, r *http.Request) { ) return } + if peerNode.IsFailOver { + logic.ReturnErrorResponse( + w, + r, + logic.FormatError(errors.New("peer is acting as failover"), "badrequest"), + ) + return + } if node.IsRelayed && node.RelayedBy == peerNode.ID.String() { logic.ReturnErrorResponse( w, diff --git a/pro/logic/failover.go b/pro/logic/failover.go index 788e09e0b..4b0debdca 100644 --- a/pro/logic/failover.go +++ b/pro/logic/failover.go @@ -3,6 +3,7 @@ package logic import ( "errors" "net" + "sync" "github.com/google/uuid" "github.com/gravitl/netmaker/logger" @@ -11,8 +12,11 @@ import ( "golang.org/x/exp/slog" ) -func SetFailOverCtx(failOverNode, victimNode, peerNode models.Node) error { +var failOverCtxMutex = &sync.RWMutex{} +func SetFailOverCtx(failOverNode, victimNode, peerNode models.Node) error { + failOverCtxMutex.Lock() + defer failOverCtxMutex.Unlock() if peerNode.FailOverPeers == nil { peerNode.FailOverPeers = make(map[string]struct{}) }