From 6f60551f0271bebedecb0634bf51e10a2cabd542 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Fri, 22 Nov 2024 19:14:50 +0400 Subject: [PATCH 1/2] add failover ctx mutex --- pro/logic/failover.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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{}) } From 44769aff31f9f68adf78ff66c492655419d67822 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Fri, 22 Nov 2024 19:31:50 +0400 Subject: [PATCH 2/2] ignore request to failover peer --- pro/controllers/failover.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pro/controllers/failover.go b/pro/controllers/failover.go index 946e753e4..92c3ca85b 100644 --- a/pro/controllers/failover.go +++ b/pro/controllers/failover.go @@ -211,6 +211,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,