diff --git a/server/internal/api/websocket.go b/server/internal/api/websocket.go index 5d2c308..c7b072e 100644 --- a/server/internal/api/websocket.go +++ b/server/internal/api/websocket.go @@ -121,8 +121,10 @@ type WSHub struct { func NewWSHub(database *db.Database) *WSHub { // Reset any rows that were left "online" by a previous server crash/restart. // Agents will re-authenticate and flip themselves back to online within seconds. - if err := database.MarkAllAgentsOffline(); err != nil { - log.Printf("[hub] startup offline reset: %v", err) + if database != nil { + if err := database.MarkAllAgentsOffline(); err != nil { + log.Printf("[hub] startup offline reset: %v", err) + } } h := &WSHub{ @@ -148,6 +150,9 @@ func NewWSHub(database *db.Database) *WSHub { // last_seen timestamp is stale (> 3 minutes without a stats message). // It also notifies the dashboard so client state stays in sync. func (h *WSHub) runStaleAgentSweep() { + if h.db == nil { + return + } const staleness = 3 * time.Minute ticker := time.NewTicker(45 * time.Second) defer ticker.Stop()