Browse Source

Merge pull request #1629 from gravitl/bugfix_0.16.2_zombies

re-enable zombie processing
Alex Feiszli 2 years ago
parent
commit
22c741bd51
3 changed files with 10 additions and 3 deletions
  1. 1 1
      logic/nodes.go
  2. 9 1
      logic/zombie.go
  3. 0 1
      main.go

+ 1 - 1
logic/nodes.go

@@ -335,7 +335,7 @@ func CreateNode(node *models.Node) error {
 	if err != nil {
 		return err
 	}
-	// CheckZombies(node)
+	CheckZombies(node)
 
 	nodebytes, err := json.Marshal(&node)
 	if err != nil {

+ 9 - 1
logic/zombie.go

@@ -31,6 +31,7 @@ func CheckZombies(newnode *models.Node) {
 	}
 	for _, node := range nodes {
 		if node.MacAddress == newnode.MacAddress {
+			logger.Log(0, "adding ", node.ID, " to zombie list")
 			newZombie <- node.ID
 		}
 	}
@@ -38,6 +39,8 @@ func CheckZombies(newnode *models.Node) {
 
 // ManageZombies - goroutine which adds/removes/deletes nodes from the zombie node quarantine list
 func ManageZombies(ctx context.Context) {
+	logger.Log(2, "Zombie management started")
+	InitializeZombies()
 	for {
 		select {
 		case <-ctx.Done():
@@ -60,11 +63,14 @@ func ManageZombies(ctx context.Context) {
 				logger.Log(3, "no zombies found")
 			}
 		case <-time.After(time.Second * ZOMBIE_TIMEOUT):
+			logger.Log(0, "checking for zombie nodes")
 			if len(zombies) > 0 {
 				for i := len(zombies) - 1; i >= 0; i-- {
 					node, err := GetNodeByID(zombies[i])
 					if err != nil {
 						logger.Log(1, "error retrieving zombie node", zombies[i], err.Error())
+						logger.Log(1, "deleting ", node.Name, " from zombie list")
+						zombies = append(zombies[:i], zombies[i+1:]...)
 						continue
 					}
 					if time.Since(time.Unix(node.LastCheckIn, 0)) > time.Minute*ZOMBIE_DELETE_TIME {
@@ -82,7 +88,7 @@ func ManageZombies(ctx context.Context) {
 }
 
 // InitializeZombies - populates the zombie quarantine list (should be called from initialization)
-func InitalizeZombies() {
+func InitializeZombies() {
 	nodes, err := GetAllNodes()
 	if err != nil {
 		logger.Log(1, "failed to retrieve nodes", err.Error())
@@ -101,8 +107,10 @@ func InitalizeZombies() {
 			if node.MacAddress == othernode.MacAddress {
 				if node.LastCheckIn > othernode.LastCheckIn {
 					zombies = append(zombies, othernode.ID)
+					logger.Log(1, "adding ", othernode.Name, " with ID ", othernode.ID, " to zombie list")
 				} else {
 					zombies = append(zombies, node.ID)
+					logger.Log(1, "adding ", node.Name, " with ID ", node.ID, " to zombie list")
 				}
 			}
 		}

+ 0 - 1
main.go

@@ -134,7 +134,6 @@ func initialize() { // Client Mode Prereq Check
 			logger.Log(0, "error occurred when notifying nodes of startup", err.Error())
 		}
 	}
-	logic.InitalizeZombies()
 }
 
 func startControllers() {