Fix remote API (Fabric/API key): 429 handling, NVR filter, updateWeb nil panic (#958)

This commit is contained in:
Brian Gates
2026-02-18 06:34:04 -05:00
committed by GitHub
parent 4bf5c1e6b5
commit 074595c0a9
7 changed files with 129 additions and 20 deletions

View File

@@ -100,6 +100,9 @@ func (u *InputUnifi) pollController(c *Controller) (*poller.Metrics, error) {
u.RLock()
defer u.RUnlock()
if c == nil {
return nil, fmt.Errorf("controller is nil")
}
if c.Unifi == nil {
return nil, fmt.Errorf("controller client is nil (e.g. after 429 or auth failure): %s", c.URL)
}
@@ -113,7 +116,6 @@ func (u *InputUnifi) pollController(c *Controller) (*poller.Metrics, error) {
}
m := &Metrics{TS: time.Now(), Sites: sites}
defer updateWeb(c, m)
// FIXME needs to be last poll time maybe
st := m.TS.Add(-1 * pollDuration)
@@ -210,6 +212,18 @@ func (u *InputUnifi) pollController(c *Controller) (*poller.Metrics, error) {
u.LogDebugf("Found %d Sysinfo entries", len(m.Sysinfos))
}
// Update web UI only on success; call explicitly so we never run with nil c/c.Unifi (no defer).
// Recover so a panic in updateWeb (e.g. old image, race) never kills the poller.
if c != nil && c.Unifi != nil {
func() {
defer func() {
if r := recover(); r != nil {
u.LogErrorf("updateWeb panic recovered (upgrade image if this persists): %v", r)
}
}()
updateWeb(c, m)
}()
}
return u.augmentMetrics(c, m), nil
}