Improve MQTT subscriber resilience
- Remove max reconnect attempts limit (was 10) - MQTT subscriber now retries indefinitely until connection succeeds - Reduce log spam by logging only first 10 attempts, then every 10th - Prevents permanent connection loss after temporary network issues 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,6 @@ interface OwnTracksMessage {
|
||||
class MQTTSubscriber {
|
||||
private client: mqtt.MqttClient | null = null;
|
||||
private reconnectAttempts = 0;
|
||||
private maxReconnectAttempts = 10;
|
||||
private isConnecting = false;
|
||||
|
||||
constructor(
|
||||
@@ -80,11 +79,9 @@ class MQTTSubscriber {
|
||||
|
||||
this.client.on('reconnect', () => {
|
||||
this.reconnectAttempts++;
|
||||
console.log(`Reconnecting to MQTT broker (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`);
|
||||
|
||||
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
||||
console.error('Max reconnect attempts reached, giving up');
|
||||
this.client?.end();
|
||||
// Log less frequently to avoid spam (every 10th attempt after attempt 10)
|
||||
if (this.reconnectAttempts <= 10 || this.reconnectAttempts % 10 === 0) {
|
||||
console.log(`Reconnecting to MQTT broker (attempt ${this.reconnectAttempts})`);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user