peers: clean up peer links when an agent is killed
RemoveAgent now iterates remaining agents and removes any peer link pointing to the removed agent's name, preventing stale/corrupt state.
This commit is contained in:
parent
7055444748
commit
86b5039552
|
|
@ -296,11 +296,14 @@ func (s *Session) AddAgent(ag *agent.Agent) {
|
|||
}
|
||||
|
||||
// RemoveAgent removes an agent by ID and closes it.
|
||||
// Any peer relationships to this agent are cleaned up from remaining agents.
|
||||
func (s *Session) RemoveAgent(id string) bool {
|
||||
idx := -1
|
||||
var removed *agent.Agent
|
||||
for i, ag := range s.agents {
|
||||
if ag.ID() == id {
|
||||
idx = i
|
||||
removed = ag
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -309,6 +312,12 @@ func (s *Session) RemoveAgent(id string) bool {
|
|||
}
|
||||
s.agents[idx].Close()
|
||||
s.agents = append(s.agents[:idx], s.agents[idx+1:]...)
|
||||
|
||||
// Remove peer links pointing to the removed agent.
|
||||
name := removed.Name()
|
||||
for _, ag := range s.agents {
|
||||
ag.RemovePeer(name)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue