From 138313a3eb10f16661e3fc56eddac06dccc2aef6 Mon Sep 17 00:00:00 2001 From: shipmints Date: Fri, 14 Feb 2020 20:36:17 -0500 Subject: [PATCH] Corrected memory leak of task refs in client deliver_message on timeout causing client_tasks to grow forever, in plugin/manager causing _fired_events to grow forever --- hbmqtt/client.py | 1 + hbmqtt/plugins/manager.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/hbmqtt/client.py b/hbmqtt/client.py index 77cf442..7eb8f8a 100644 --- a/hbmqtt/client.py +++ b/hbmqtt/client.py @@ -358,6 +358,7 @@ class MQTTClient: else: #timeout occured before message received deliver_task.cancel() + self.client_tasks.pop() raise asyncio.TimeoutError @asyncio.coroutine diff --git a/hbmqtt/plugins/manager.py b/hbmqtt/plugins/manager.py index 953b360..7a923a8 100644 --- a/hbmqtt/plugins/manager.py +++ b/hbmqtt/plugins/manager.py @@ -136,7 +136,7 @@ class PluginManager: def clean_fired_events(future): try: - self._fired_events.remove(task) + self._fired_events.remove(future) except (KeyError, ValueError): pass @@ -149,6 +149,7 @@ class PluginManager: if wait: if tasks: yield from asyncio.wait(tasks, loop=self._loop) + self.logger.debug("Plugins len(_fired_events)=%d" % (len(self._fired_events))) @asyncio.coroutine def map(self, coro, *args, **kwargs):