fix acl mutex lock

This commit is contained in:
abhishek9686 2024-03-04 13:11:51 +07:00
parent f165f5fcf4
commit c25a732015
3 changed files with 3 additions and 18 deletions

View file

@ -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
}

View file

@ -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)
}

View file

@ -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
}