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.