From 463cf293863090160f96d90271ff4401f2b47d24 Mon Sep 17 00:00:00 2001 From: Josh Hawkins <32435876+hawkeye217@users.noreply.github.com> Date: Thu, 22 Oct 2026 15:15:43 -0500 Subject: [PATCH] materialize event counts in metrics endpoint The metrics endpoint stored a lazy peewee query on the shared Prometheus collector, and collect() ran it later. Overlapping scrapes run in separate threadpool threads, so two requests could execute and step the same query's sqlite cursor at once. The rows are now read with list() before they reach the collector. --- frigate/api/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frigate/api/app.py b/frigate/api/app.py index 8f0fcb5f06..c500f2b141 100644 --- a/frigate/api/app.py +++ b/frigate/api/app.py @@ -177,7 +177,9 @@ def metrics(request: Request): # Retrieve the latest statistics and update the Prometheus metrics stats = request.app.stats_emitter.get_latest_stats() # query DB for count of events by camera, label - event_counts: list[dict[str, Any]] = ( + # Materialize the rows; the collector is shared across request threads and a + # lazy query would step one sqlite cursor from two threads. + event_counts: list[dict[str, Any]] = list( Event.select(Event.camera, Event.label, fn.Count()) .group_by(Event.camera, Event.label) .dicts()