diff --git a/platypush/plugins/mqtt/__init__.py b/platypush/plugins/mqtt/__init__.py index a43c037732..d6dc1dd08e 100644 --- a/platypush/plugins/mqtt/__init__.py +++ b/platypush/plugins/mqtt/__init__.py @@ -479,8 +479,9 @@ class MqttPlugin(RunnablePlugin): client.stop() del client - @staticmethod - def _response_callback(reply_topic: str, event: threading.Event, buffer: IO[bytes]): + def _response_callback( + self, reply_topic: str, event: threading.Event, buffer: IO[bytes] + ): """ A response callback that writes the response to an IOBuffer and stops the client loop. @@ -490,9 +491,15 @@ class MqttPlugin(RunnablePlugin): if msg.topic != reply_topic: return - buffer.write(msg.payload) - client.loop_stop() - event.set() + try: + buffer.write(msg.payload) + client.loop_stop() + except Exception as e: + self.logger.warning( + 'Could not write the response back to the MQTT client: %s', e + ) + finally: + event.set() return on_message