ข้ามไปยังเนื้อหา

Issue: Frigate NVR (194.1.0.4) memory exhaustion — short-term mitigation applied

  • Date: 2026-08-01 (change executed 2026-08-01T21:21:56+07:00)
  • GitHub issue: racksync/obh-iot#9
  • Status: Short-term mitigation applied 2026-08-01, but memory crept back up over ~3 days and triggered a live-view outage 2026-08-04 — see “Recurrence” below. Manually restarted, recovered. Long-term fix (RAM upgrade / camera load reduction) still open
  • Area: Frigate NVR / 194.1.0.4 (RILF-FRIGATE) / Docker
  • Reported by: Damrongwit — video stopped showing, manually ssh fg via gateway and restarted the container himself, video came back
  • Owner: RACKSYNC (Damrongwit)

CCTV video stopped displaying. User SSH’d into fg (194.1.0.4) via the gateway and manually restarted the frigate container; video recovered immediately.

docker inspect frigate on the container the user had just restarted showed OOMKilled=false, ExitCode=0, RestartCount=0 — the prior instance was cleanly stopped by the user’s own command, not killed by the kernel. dmesg had no OOM entries for 2026-07-31 or 2026-08-01. The likely explanation: the process was alive but unresponsive under severe memory/swap pressure (see below), rather than being killed outright — so Docker’s restart: unless-stopped policy never triggered automatically, and manual intervention was needed.

docker stats immediately after the user’s restart showed frigate already at 6.308 GiB / 7.448 GiB (84.69%) of total host RAM, roughly one hour after starting — climbing fast, with no memory limit configured (HostConfig.Memory=0 = unlimited) and swap 975 MiB used / ~12 KiB free (essentially full).

dmesg -T | grep "Out of memory" showed the kernel OOM-killer terminating Frigate’s python3 process at nearly the same clock time on 14 of the 15 days from 2026-07-17 to 2026-07-30, each time at 2.9–3.2 GB RSS:

Mon Jul 27 11:47:50 Killed process (python3) anon-rss:2941024kB
Tue Jul 28 11:49:05 Killed process (python3) anon-rss:2981960kB
Wed Jul 29 11:47:57 Killed process (python3) anon-rss:3026060kB
Thu Jul 30 11:48:02 Killed process (python3) anon-rss:2989380kB

(11:47–11:49 UTC = 18:47–18:49 +07 — evening, near dusk. Cause of the exact timing not determined; possibly related to all-camera IR-cut/night-mode transition around the same time.)

This matches #9, opened from the 2026-07-10 security/reliability audit, which found nearly identical symptoms three weeks earlier (7.4 GiB total, ~298 MB available, Frigate RSS 2.6 GB, container uptime only 18 h against a 333-day host uptime — meaning it had already been restarted shortly before that audit too). This is a chronic, unresolved condition, not a one-off.

/home/mtd/frigate/docker-compose.yml reserved RAM well beyond what 13 cameras need:

Setting Value What it’s for
shm_size 4096mb (4 GB) shared memory for frame buffers
tmpfs /tmp/cache 2000000000 (~1.9 GB) segment cache before flush to disk
Fixed total ~5.9 GB reserved before the Frigate process itself uses anything

All 13 cameras run detection at 1280×720. Frigate’s documented shm sizing guideline (≈40 MB + 2.5 MB/MP per camera) gives ≈550 MB for this fleet — the configured 4096 MB was roughly 7× oversized. With ~5.9 GB already committed to fixed RAM-backed buffers on a 7.4 GiB host, and the Frigate process itself needing 2.6–3.2 GB (per the OOM evidence above), total demand structurally exceeded physical RAM. This is why it fails on a predictable schedule rather than randomly.

⚠️ While reading config.yml to check camera resolutions, the MQTT password appeared in plaintext in the tool output. It was not written to any file, commit, or GitHub comment. Flagging here as a reason to rotate it — see #13.

Executed: 2026-08-01T21:21:56+07:00 by RACKSYNC (Damrongwit), via Claude Code, ssh fg over the gateway.

Edited /home/mtd/frigate/docker-compose.yml, three changes to the frigate service:

Setting Before After Rationale
shm_size "4096mb" "1024mb" ~2× the calculated ≈550 MB need, well above what 13×720p cameras require
tmpfs /tmp/cache size 2000000000 1000000000 halved; still a meaningful disk-write buffer
mem_limit (none — unlimited) "6800m" hard ceiling so Docker cgroup-OOM-kills and auto-restarts the container within its own boundary if it ever leaks again, instead of the kernel starving the whole host (and everything else on it: sshd, node-exporter, dockerd)

Net effect: fixed RAM-backed reservation dropped from ~5.9 GB to ~1.95 GB, leaving ~4.85 GB of headroom inside the 6.8 GB container ceiling for the actual process — comfortably above its observed 2.6–3.2 GB need — while still leaving ~600 MB free for the host OS outside the container.

Pre-change copy (host) /home/mtd/frigate/docker-compose.yml.bak-20260801-212156
Pre-change copy (off-host) /Volumes/SmileX-Storage/backup/obh-iot/fg-194.1.0.4/frigate-compose-2026-08-01/docker-compose.yml.before
sha256 before 63a0fd0944f528540af7e157ec3f50956a8252760509d98ea452be2c8c169391
sha256 after ac3a2420c521e6fef5c928e115bb392b71fe212d3de0021023e8a2a896771e5e

Rollback:

Terminal window
ssh fg
cd /home/mtd/frigate
sudo cp docker-compose.yml.bak-20260801-212156 docker-compose.yml
sha256sum docker-compose.yml # must be 63a0fd09…
docker compose up -d

This will briefly interrupt video/recording while the container recreates, same as the change itself.

  • docker inspect: Memory=7130316800 (6800 MB) · ShmSize=1073741824 (1024 MB) applied correctly
  • Health=healthy · Restarting=false · OOMKilled=false · RestartCount=0 — no crash loop
  • Container memory: 3.68 GiB / 6.64 GiB (55.5%) shortly after restart, vs 84.7% of the whole host before the fix
  • Host: available memory rose 1.7 GiB → 3.0 GiB; swap in use dropped 975 MiB → 89 MiB
  • Frigate API /api/stats: 12 of 13 cameras streaming normally (capture_fps ≈ 5.0)
  • Coral USB detector: inference_speed=9.1ms, healthy

frigate_cam_18 shows capture_fps=0 / detect_fps=0. Its logs show a continuous 401 Unauthorized RTSP auth failure against 192.1.2.46 (crash-restart loop on that one camera’s ffmpeg process, independent of the memory issue above — it was failing before this change too). Needs its RTSP credentials checked on the camera/NVR side. Not filed as a separate issue yet.

All 13 camera tiles in the Frigate UI live view showed “No frames have been received, check error logs” simultaneously. Reported by Damrongwit with a screenshot.

docker inspect showed the container itself was still Health=healthy, RestartCount=0, OOMKilled=false — not crashed. docker stats showed memory at 91.9% of the 6800m limit (up from 55.5% three days earlier), having climbed steadily since the 2026-08-01 fix. Frigate’s own /api/stats showed 12/13 cameras still capturing at a normal ~5.0 capture_fps — the RTSP capture pipeline itself was never interrupted.

The actual failure was isolated to docker logs frigate: /live/jsmpeg/frigate_cam_* WebSocket handshakes, normally ~2s, were taking 28–31s to complete — long enough for the browser to give up and show the “no frames” placeholder. frigate.record.maintainer was also logging Too many unprocessed recording segments in cache for frigate_cam_21 and frigate_cam_15, confirming the whole process was under genuine load, not just the live-view path.

Root cause of the memory climb (separate diagnosis, done before this outage): frigate_cam_05 had accumulated 9 tracked “car” events that opened over a ~1-hour window and never closed (end_time: null, ages 20–21h at time of check) — almost certainly a stationary/parked vehicle sitting in that camera’s objects.filters.car.mask zone that Frigate kept re-opening tracking for instead of resolving into one closed detection. This explained cam_05’s outlier CPU (66%) and detection_fps (11.4 vs. its own 5.0 capture rate) seen in an earlier check that day, and — per this outage — was consuming enough of the main process’s attention/memory to starve new WebSocket connections once the backlog got large enough.

Executed: 2026-08-04T23:53:11+07:00 (StartedAt, Bangkok time) by RACKSYNC (Damrongwit), via Claude Code, ssh fg over the gateway. No config file changed — docker restart frigate only (clears in-memory state, including the stuck cam_05 events; the 2026-08-01 compose settings were left as-is).

Before (23:52:53+07:00) After (23:53:22+07:00, ~10s post-start)
Memory 6.103 GiB / 6.641 GiB (91.90%) 3.583 GiB / 6.641 GiB (53.95%)
Health healthy (but live view starved) starting → healthy within ~30s
Cameras streaming 12/13 (capture_fps≈5.0), live-view broken on all 13 12/13 capture_fps≈5.0 restored within ~1 min, live view working

No rollback needed (no file modified) — if it needs undoing, just docker restart frigate again.

  • Health=healthy, OOMKilled=false, RestartCount=0 (manual docker restart doesn’t increment Docker’s own restart-policy counter)
  • Memory held at 64.9% the next morning (2026-08-05), noticeably slower to climb back than the 55.5%→91.9% trajectory over the prior 3 days — consistent with cam_05’s stuck-event backlog being the main driver, now cleared
  • frigate_cam_18 still shows capture_fps=0 — confirmed unrelated pre-existing RTSP 401 issue, untouched by this restart
  • cam_05 stuck-event root cause is now the priority long-term item (promoted above the general RAM/load options below): investigate objects.stationary tuning for this camera so a parked/stationary “car” doesn’t keep spawning new never-closing tracked events. A scheduled/periodic Frigate restart would be a blunt mitigation if the config fix takes longer, since restart demonstrably clears the backlog and costs only a few seconds of video interruption
  • Watch whether the 18:47–18:49 daily OOM pattern recurs under the new limits (it should now show up as a Docker-level restart of just this container, not a host-wide event — check docker inspect frigate --format RestartCount periodically over the next few days)
  • Confirm the exact cause of the near-dusk timing (IR-cut/night-mode transition across cameras vs. coincidence)
  • Fix frigate_cam_18 RTSP auth (separate, pre-existing issue)
  • Rotate the MQTT password (visible in config.yml) — see #13
  • Long-term fix — this mitigation buys headroom, it does not remove the underlying constraint of 13 cameras on a 7.4 GiB machine. Options captured on #9 and ma/2570/md/plan.md §5.3: physical RAM upgrade, reduce per-camera detect resolution/fps, or move some cameras to a second Frigate instance