From 24fe4281b4b1fc4c37f52b0fde4349e56ea0e353 Mon Sep 17 00:00:00 2001 From: Kyle Agronick Date: Tue, 27 Nov 2018 13:21:06 -0500 Subject: [PATCH] Clean up receive_buffer. Fixes memory leak. (#141) Refs django/channels#1181 --- channels_redis/core.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/channels_redis/core.py b/channels_redis/core.py index bc6e496..669be2a 100644 --- a/channels_redis/core.py +++ b/channels_redis/core.py @@ -383,6 +383,7 @@ async def receive(self, channel): except asyncio.CancelledError: # Ensure all tasks are cancelled if we are cancelled. # Also see: https://bugs.python.org/issue23859 + del self.receive_buffer[channel] for task in tasks: if not task.cancel(): assert task.done() @@ -433,6 +434,9 @@ async def receive(self, channel): else: self.receive_buffer[message_channel].put_nowait(message) message = None + except: + del self.receive_buffer[channel] + raise finally: self.receive_lock.release()