MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / CleanupInactiveSessions

Method CleanupInactiveSessions

internal/vnc/session_manager.go:572–619  ·  view source on GitHub ↗

CleanupInactiveSessions removes sessions that haven't been accessed recently.

(maxAge time.Duration)

Source from the content-addressed store, hash-verified

570
571// CleanupInactiveSessions removes sessions that haven't been accessed recently.
572func (sm *SessionManager) CleanupInactiveSessions(maxAge time.Duration) {
573 sm.mutex.Lock()
574 defer sm.mutex.Unlock()
575
576 var expiredSessions []string
577
578 // Find expired sessions
579 for sessionID, session := range sm.sessions {
580 if session.IsExpired(maxAge) {
581 expiredSessions = append(expiredSessions, sessionID)
582 }
583 }
584
585 // Only log and clean up if there are expired sessions
586 if len(expiredSessions) == 0 {
587 return
588 }
589
590 if sm.logger != nil {
591 sm.logger.Info("Found %d expired VNC sessions to clean up", len(expiredSessions))
592 }
593
594 // Clean up expired sessions
595 for _, sessionID := range expiredSessions {
596 session := sm.sessions[sessionID]
597
598 if sm.logger != nil {
599 sm.logger.Info("Cleaning up expired VNC session: session_id=%s, target_type=%s, target_name=%s, age=%v, inactive_for=%v",
600 sessionID, session.TargetType, session.TargetName, time.Since(session.CreatedAt), time.Since(session.LastUsed))
601 }
602
603 // Shutdown the session
604 if err := session.Shutdown(); err != nil && sm.logger != nil {
605 sm.logger.Error("Failed to shutdown expired session: session_id=%s, error=%v", sessionID, err)
606 }
607
608 // Remove from sessions map
609 delete(sm.sessions, sessionID)
610 }
611
612 // Notify callback of session count change
613 sm.notifySessionCountChange()
614
615 if sm.logger != nil {
616 sm.logger.Info("Completed VNC session cleanup: cleaned_sessions=%d, remaining_sessions=%d",
617 len(expiredSessions), len(sm.sessions))
618 }
619}
620
621// Shutdown gracefully shuts down the session manager and all active sessions.
622// This should be called when the application is shutting down to ensure

Callers

nothing calls this directly

Calls 5

IsExpiredMethod · 0.80
InfoMethod · 0.65
ShutdownMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected