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) <noreply@anthropic.com>
This commit is contained in:
Alex Vanderpot
2026-06-15 21:54:10 -04:00
parent 281f4ab25b
commit d0cc83af7d
2 changed files with 5 additions and 1 deletions
+1
View File
@@ -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}
+4 -1
View File
@@ -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.