Issue: Gateway nf_conntrack table exhaustion — external access outage (rilf-iot)
- Date: 2026-07-06 (outage observed ~morning; recovered 11:48 +07:00 by VM reboot)
- GitHub issue: racksync/obh-iot#2
- Status: Investigated (read-only) — fix pending decision
- Area: Gateway VM 194.1.0.3 / Cloudflare Tunnel / kernel netfilter
- Reported by: Surasak.Sato (hospital IT, via LINE 11:51) — restarted gateway as first aid
- Owner: RACKSYNC (Damrongwit)
Symptom
หัวข้อที่มีชื่อว่า “Symptom”External access to the RILF IoT system (Cloudflare Tunnel routes) failed this morning. Other hospital systems were fine; internal access to 194.1.0.1 (HA) was normal. Surasak rebooted the gateway VM at 11:48 and external access recovered immediately.
Root cause (confirmed from logs)
หัวข้อที่มีชื่อว่า “Root cause (confirmed from logs)”The gateway’s kernel connection-tracking table filled to its limit (65,536 entries) after 69 days of uptime. When full, the kernel drops all new connections:
kernel: nf_conntrack: nf_conntrack: table full, dropping packet (continuous until 11:48 reboot)cloudflared: Unable to reach the origin service ... i/o timeout (all internal origins .2/.5/.11/.13)cloudflared: Failed to refresh DNS local resolver ... write udp → 194.1.1.254:53: operation not permittedChain: table full → new packets dropped → cloudflared cannot reach origins nor refresh its edge DNS → tunnel drops off the Cloudflare edge → external access dies while all origin servers stay healthy internally (exactly the reported symptom). Reboot cleared the table → recovery.
Why it will recur
หัวข้อที่มีชื่อว่า “Why it will recur”Reboot history shows a fill-and-reboot pattern roughly every 50–70 days: 2025-09-18 → 11-19 → 2026-01-20 → 03-11 → 04-27 → 07-06.
Contributing factors (verified on host, post-reboot):
| Setting | Value | Note |
|---|---|---|
nf_conntrack_max |
65,536 | kernel default, never tuned (no persistent sysctl) |
nf_conntrack_tcp_timeout_established |
432,000 s (5 days) | idle entries linger for days |
| Role | NAT gateway (ip_forward=1, Docker MASQUERADE) + cloudflared proxying 43 routes |
steady entry consumption |
| RAM | 4 GB (2.9 GB free) | headroom exists for a larger table |
| node-exporter | already exposes node_nf_conntrack_entries / _limit |
alerting is possible today |
Post-reboot health check (12:46): conntrack 177/65,536; cloudflared Up, 0 errors in 30 min.
Proposed fixes (pending decision — NOT executed)
หัวข้อที่มีชื่อว่า “Proposed fixes (pending decision — NOT executed)”- 1. Prometheus alert at ~80% of conntrack limit — DONE 2026-07-06 ~13:30 +07:
- Prerequisite discovered & fixed: gateway node-exporter ran on a Docker bridge
network, so
node_nf_conntrack_entriesreported the container’s netns (~3) instead of the host’s (~150) — the alert would never have fired. Changed/home/mtd/metrics-monitoring/docker-compose.ymltonetwork_mode: host(backup:docker-compose.yml.bak-20260706-132552; cloudflared untouched — verified identical StartedAt). Metric now matches host exactly - Alert deployed via GitOps:
GatewayConntrackHigh(warning, >80% for 15m) committed toracksync/obh-monitor@73bfc18, deployed by the update-prometheus-config workflow; reload done manually (see workflow bug below). Verified: 22 rules loaded, new ruleinactive(usage 0.25%), all 21 prior alerts intact, no new firing caused by the change - Workflow bug found (follow-up below): the reload step runs
docker compose psin the checkout dir instead of/home/mtd/metrics, thinks Prometheus is down, and fails trying to start a duplicate stack (network pool overlap). Harmless but breaks the workflow’s reload; deploy+validate steps work fine
- Prerequisite discovered & fixed: gateway node-exporter ran on a Docker bridge
network, so
- 1b. Fix reload step in obh-monitor
update-prometheus-config.yml—cd /home/mtd/metricsbeforedocker compose ps/ reload - 1c. Fleet-wide: other node-exporters (db, iot-app, monitor, frigate, imageshare) have the same container-netns issue — conntrack/network metrics are per-container, not host. Only gateway fixed today (it’s the NAT host, highest risk). Consider host network for the rest
- 2. Raise
nf_conntrack_maxto 262,144 (+ hashsize 65,536) — DONE 2026-07-06 13:55 +07, zero downtime, applied runtime then persisted. Executed via the HA-jump path (ssh -J hassio@cf-rilf-ha root@194.1.0.3) so the working shell did not depend on the gateway’s own tunnel. Baseline recorded: max=65536 hashsize=16384 count=183 - 3. Shorten
nf_conntrack_tcp_timeout_established432,000s (5d) → 86,400s (1d) — DONE same session. Existing entries keep their timers until next packet (no eviction) - Persisted in three NEW files (nothing pre-existing was modified — rollback = delete):/etc/sysctl.d/99-conntrack.conf,/etc/modules-load.d/nf_conntrack.conf(module loads before systemd-sysctl at boot),/etc/modprobe.d/nf_conntrack.conf(hashsize) - Verified after change: dmesg clean, cloudflared 0 errors, direct tunnel path OK, Prometheusnode_nf_conntrack_entries_limit{node-gateway}= 262144,GatewayConntrackHighinactive - 4. Optional: watch conntrack growth over coming days to rule out a specific leaking client (top consumers by source)
- Cross-check after fix: verify table stays <50% across a multi-week window; annotate Grafana with the change date
Post-fix verification (2026-07-06 14:21 +07) — 12-point re-check PASSED
หัวข้อที่มีชื่อว่า “Post-fix verification (2026-07-06 14:21 +07) — 12-point re-check PASSED”Gateway (via HA-jump): runtime values 262144/65536/86400 ✓, 3 persist files +
sysctl -p clean ✓, exporter host-mode metric == host truth (250=250) ✓,
cloudflared 0 ERR/10min ✓, dmesg clean ✓.
Prometheus (via direct tunnel — proves gateway tunnel healthy): 22 rules ✓,
GatewayConntrackHigh inactive (0.09%) ✓, limit metric 262144 ✓, target up ✓,
only 5 pre-existing alerts firing (none from this work) ✓, healthy ✓.
Items 1+2+3 complete and verified — the ~50–70 day fill-and-crash cycle is broken
(4× headroom + 5× faster idle reclaim), alert as ratio-based safety net.
Remaining before close: 1b, 1c, multi-week <50% cross-check, and (related)
node-ha stale scrape target since HA OS migration (2026-05-31).
Constraints / notes
หัวข้อที่มีชื่อว่า “Constraints / notes”- Per constitution: commit repo state before any remote change; changes on the gateway affect all 43 tunnel routes → schedule brief window and inform hospital IT (Surasak)
- Sysctl changes (#2/#3) are runtime-applied (no reboot needed) but MUST be persisted to survive the next reboot