perf(ui): probe sources asynchronously so /api/status no longer blocks on upstream reachability

ensureProbe() called Registry.ProbeAll() synchronously on every status request when >30s had passed since the last probe, blocking the response on the slowest upstream (zen ~1s, frank ~1.9s, total ~1.5s) — this stalled WebUI page loads and tab switches. Now the probe runs in a background goroutine (15s budget); status returns in ~7ms and the 3s stats poll picks up updated reachability next tick. Deployed (bak .bak.20260811s), server active.
This commit is contained in:
root
2026-08-11 17:37:49 +08:00
parent 5ca3b7f680
commit c006c3988e

View File

@ -377,6 +377,9 @@ func (g *Gateway) handleModels(w http.ResponseWriter, r *http.Request) {
}
// ensureProbe triggers a live source probe at most once every 30s.
// The probe runs asynchronously so a slow/stuck upstream never blocks the
// status response — reachability data is eventually-consistent and the UI
// polls /api/stats every 3s anyway, so the next refresh picks it up.
func (g *Gateway) ensureProbe(ctx context.Context) {
g.probeMu.Lock()
due := time.Since(g.lastProbe) > 30*time.Second
@ -384,9 +387,14 @@ func (g *Gateway) ensureProbe(ctx context.Context) {
g.lastProbe = time.Now()
}
g.probeMu.Unlock()
if due {
g.core.Registry().ProbeAll(ctx)
if !due {
return
}
go func() {
probeCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
g.core.Registry().ProbeAll(probeCtx)
}()
}
// handleResetHealth (admin) clears the per-source backoff state so a fixed