fix: only delete expired agents on success (#11940)

This commit is contained in:
Colin Adler 2024-01-30 14:11:45 -06:00 committed by GitHub
parent 27f3b7a814
commit 2fd1a726aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -206,12 +206,13 @@ func (s *ServerTailnet) doExpireOldAgents(cutoff time.Duration) {
// If no one has connected since the cutoff and there are no active
// connections, remove the agent.
if time.Since(lastConnection) > cutoff && len(s.agentTickets[agentID]) == 0 {
deletedCount++
delete(s.agentConnectionTimes, agentID)
err := agentConn.UnsubscribeAgent(agentID)
if err != nil {
s.logger.Error(ctx, "unsubscribe expired agent", slog.Error(err), slog.F("agent_id", agentID))
continue
}
deletedCount++
delete(s.agentConnectionTimes, agentID)
}
}
s.nodesMu.Unlock()