From d0cc83af7d6c51aae4b51f3a2758bfddd10faeb8 Mon Sep 17 00:00:00 2001 From: Alex Vanderpot Date: Mon, 15 Jun 2026 21:54:10 -0400 Subject: [PATCH] ingest: make MQTT KeepAlive configurable (MQTT_KEEPALIVE_SECONDS) As a near-silent subscriber, paho emits a PINGREQ roughly every KeepAlive seconds; lowering it sends client->server frames more often to keep the Cloudflare-proxied WebSocket path warm in both directions, a lever for the residual mid-stream "pingresp not received" stalls on the letsmesh broker. Default unchanged (30s); wired through docker-compose. Co-Authored-By: Claude Opus 4.8 (1M context) --- docker-compose.yml | 1 + ingest/internal/ingestcommon/ingest.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 899a4d2..e11c70a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -62,6 +62,7 @@ services: - MQTT_BROKERS=${MQTT_BROKERS} - MQTT_CLIENT_ID=${MQTT_CLIENT_ID:-meshcore-ingest} - MQTT_STALE_AFTER_SECONDS=${MQTT_STALE_AFTER_SECONDS:-300} + - MQTT_KEEPALIVE_SECONDS=${MQTT_KEEPALIVE_SECONDS:-30} - MQTT_PING_TIMEOUT_SECONDS=${MQTT_PING_TIMEOUT_SECONDS:-20} - MESHCORE_BATCH_FLUSH_SECONDS=${MESHCORE_BATCH_FLUSH_SECONDS:-10} - MESHCORE_BATCH_MAX_ROWS=${MESHCORE_BATCH_MAX_ROWS:-5000} diff --git a/ingest/internal/ingestcommon/ingest.go b/ingest/internal/ingestcommon/ingest.go index 40caaf6..8eb55e4 100644 --- a/ingest/internal/ingestcommon/ingest.go +++ b/ingest/internal/ingestcommon/ingest.go @@ -146,7 +146,10 @@ func (d *Daemon) connectToBroker(broker MQTTBrokerConfig, idx int, maxRetries in opts.SetConnectRetry(true) opts.SetConnectTimeout(10 * time.Second) opts.SetMaxReconnectInterval(30 * time.Second) - opts.SetKeepAlive(30 * time.Second) + // As a near-silent subscriber we send a PINGREQ roughly every KeepAlive + // seconds; lowering it keeps the Cloudflare WebSocket path warm in the + // client->server direction (a lever for the residual mid-stream stalls). + opts.SetKeepAlive(time.Duration(GetEnvIntOrDefault("MQTT_KEEPALIVE_SECONDS", 30)) * time.Second) // Allow extra margin for PINGRESP to survive the Cloudflare WebSocket // proxy's buffering/jitter; 10s was tight and produced false // "pingresp not received" disconnects. Configurable for tuning.