From 00fabf3853fe1e9731a6d3027c033fdf5f730c0c Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 22 Mar 2021 02:11:21 +0100 Subject: [PATCH] Reverted MQTT client reconnection logic until I find a more reliable way to identify the errors that caused the disconnections --- CHANGELOG.md | 2 -- platypush/backend/mqtt.py | 20 -------------------- 2 files changed, 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0b9c0777..a4b3ca4bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,8 +11,6 @@ Given the high speed of development in the first phase, changes are being report - Fixed dashboard widgets custom classes being propagated both to the container and to the widget content [see #179] -- Added reconnection logic to `backend.mqtt` listeners in case of temporary MQTT server-side errors. - ## [0.20.6] - 2021-03-16 ### Added diff --git a/platypush/backend/mqtt.py b/platypush/backend/mqtt.py index 8722c2be8..1091ff7da 100644 --- a/platypush/backend/mqtt.py +++ b/platypush/backend/mqtt.py @@ -1,8 +1,6 @@ import json -import logging import os import threading -import time from typing import Optional, List, Callable import paho.mqtt.client as mqtt @@ -18,8 +16,6 @@ from platypush.utils import set_thread_name class MqttClient(mqtt.Client, threading.Thread): - _reconnect_timeout = 10.0 - def __init__(self, *args, host: str, port: int, topics: Optional[List[str]] = None, on_message: Optional[Callable] = None, username: Optional[str] = None, password: Optional[str] = None, client_id: Optional[str] = None, tls_cafile: Optional[str] = None, tls_certfile: Optional[str] = None, @@ -33,8 +29,6 @@ class MqttClient(mqtt.Client, threading.Thread): self.topics = set(topics or []) self.keepalive = keepalive self.on_connect = self.connect_hndl() - self.on_disconnect = self.disconnect_hndl() - self.logger = logging.getLogger(__name__) if on_message: self.on_message = on_message @@ -79,20 +73,6 @@ class MqttClient(mqtt.Client, threading.Thread): return handler - def disconnect_hndl(self): - # noinspection PyUnusedLocal - def handler(client, userdata, rc): - if not self._stop_scheduled and rc in {mqtt.MQTT_ERR_INVAL, mqtt.MQTT_ERR_AGAIN, mqtt.MQTT_ERR_CONN_LOST, - mqtt.MQTT_ERR_CONN_REFUSED, mqtt.MQTT_ERR_ERRNO, - mqtt.MQTT_ERR_NO_CONN, mqtt.MQTT_ERR_PAYLOAD_SIZE, - mqtt.MQTT_ERR_QUEUE_SIZE, mqtt.MQTT_ERR_UNKNOWN}: - self.logger.warning('Unexpected disconnection from {}:{}. MQTT error: {}'.format( - self.host, self.port, rc)) - time.sleep(self._reconnect_timeout) - self.connect(host=self.host, port=self.port, keepalive=self.keepalive) - - return handler - def run(self): super().run() self.connect(host=self.host, port=self.port, keepalive=self.keepalive)