From c25a73201566ecae36ec50613dfc95ca38f308d0 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Mon, 4 Mar 2024 13:11:51 +0700 Subject: [PATCH] fix acl mutex lock --- logic/acls/nodeacls/retrieve.go | 4 +++- logic/hosts.go | 11 ----------- logic/nodes.go | 6 ------ 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/logic/acls/nodeacls/retrieve.go b/logic/acls/nodeacls/retrieve.go index 70870e4d..15397c24 100644 --- a/logic/acls/nodeacls/retrieve.go +++ b/logic/acls/nodeacls/retrieve.go @@ -15,8 +15,10 @@ func AreNodesAllowed(networkID NetworkID, node1, node2 NodeID) bool { } var allowed bool acls.AclMutex.RLock() - allowed = currentNetworkACL[acls.AclID(node1)].IsAllowed(acls.AclID(node2)) && currentNetworkACL[acls.AclID(node2)].IsAllowed(acls.AclID(node1)) + currNetworkACLNode1 := currentNetworkACL[acls.AclID(node1)] + currNetworkACLNode2 := currentNetworkACL[acls.AclID(node2)] acls.AclMutex.RUnlock() + allowed = currNetworkACLNode1.IsAllowed(acls.AclID(node2)) && currNetworkACLNode2.IsAllowed(acls.AclID(node1)) return allowed } diff --git a/logic/hosts.go b/logic/hosts.go index d84c434a..6d8c3b28 100644 --- a/logic/hosts.go +++ b/logic/hosts.go @@ -386,7 +386,6 @@ func DissasociateNodeFromHost(n *models.Node, h *models.Host) error { if len(h.ID.String()) == 0 || h.ID == uuid.Nil { return ErrInvalidHostID } - logger.Log(0, "Hereeeee-----> 4.7.1") if n.HostID != h.ID { // check if node actually belongs to host return fmt.Errorf("node is not associated with host") } @@ -400,7 +399,6 @@ func DissasociateNodeFromHost(n *models.Node, h *models.Host) error { break } } - logger.Log(0, "Hereeeee-----> 4.7.2") if index < 0 { if len(h.Nodes) == 0 { return fmt.Errorf("node %s, not found in host, %s", n.ID.String(), h.ID.String()) @@ -408,27 +406,18 @@ func DissasociateNodeFromHost(n *models.Node, h *models.Host) error { } else { h.Nodes = RemoveStringSlice(h.Nodes, index) } - logger.Log(0, "Hereeeee-----> 4.7.3") go func() { if servercfg.IsPro { - //logger.Log(0, "Hereeeee-----> 4.7.3.1") if clients, err := GetNetworkExtClients(n.Network); err != nil { - //logger.Log(0, "Hereeeee-----> 4.7.3.2") for i := range clients { AllowClientNodeAccess(&clients[i], n.ID.String()) - //logger.Log(0, "Hereeeee-----> 4.7.3.3") } - //logger.Log(0, "Hereeeee-----> 4.7.3.4") } - //logger.Log(0, "Hereeeee-----> 4.7.3.5") - } }() - logger.Log(0, "Hereeeee-----> 4.7.4") if err := DeleteNodeByID(n); err != nil { return err } - logger.Log(0, "Hereeeee-----> 4.7.5") return UpsertHost(h) } diff --git a/logic/nodes.go b/logic/nodes.go index 7d6a2db7..7304ef54 100644 --- a/logic/nodes.go +++ b/logic/nodes.go @@ -287,32 +287,26 @@ func GetNodeByHostRef(hostid, network string) (node models.Node, err error) { func DeleteNodeByID(node *models.Node) error { var err error var key = node.ID.String() - logger.Log(0, "Hereeeee-----> 4.7.4.1") if err = database.DeleteRecord(database.NODES_TABLE_NAME, key); err != nil { if !database.IsEmptyRecord(err) { return err } } - logger.Log(0, "Hereeeee-----> 4.7.4.2") if servercfg.CacheEnabled() { deleteNodeFromCache(node.ID.String()) } - logger.Log(0, "Hereeeee-----> 4.7.4.3") if servercfg.IsDNSMode() { SetDNS() } - logger.Log(0, "Hereeeee-----> 4.7.4.4") _, err = nodeacls.RemoveNodeACL(nodeacls.NetworkID(node.Network), nodeacls.NodeID(node.ID.String())) if err != nil { // ignoring for now, could hit a nil pointer if delete called twice logger.Log(2, "attempted to remove node ACL for node", node.ID.String()) } - logger.Log(0, "Hereeeee-----> 4.7.4.5") // removeZombie <- node.ID if err = DeleteMetrics(node.ID.String()); err != nil { logger.Log(1, "unable to remove metrics from DB for node", node.ID.String(), err.Error()) } - logger.Log(0, "Hereeeee-----> 4.7.4.6") return nil }