From ee7407a7cc08ef4771b8e99969f142395c5abdec Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 15 Feb 2021 22:02:58 +0100 Subject: [PATCH] Don't create an MQTT client connection if there are no topics to subscribe. If we open multiple connections from multiple MQTT-based backends to the same host, with some of them having no topics subscribed, Paho-MQTT can mess up which client is supposed to receive which message and we may end up with lost messages on the platypush_bus_mqt/ topic. --- platypush/backend/mqtt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platypush/backend/mqtt.py b/platypush/backend/mqtt.py index 53a6e1040..40e583e56 100644 --- a/platypush/backend/mqtt.py +++ b/platypush/backend/mqtt.py @@ -319,8 +319,8 @@ class MqttBackend(Backend): def run(self): super().run() - if self.host: - topics = [self.topic] if self.subscribe_default_topic else [] + if self.host and self.subscribe_default_topic: + topics = [self.topic] client = self._get_client(host=self.host, port=self.port, topics=topics, username=self.username, password=self.password, client_id=self.client_id, tls_cafile=self.tls_cafile, tls_certfile=self.tls_certfile,