Skip to content

Commit 6031d25

Browse files
agronickandrewgodwin
authored andcommitted
Clean up receive_buffer. Fixes memory leak. (#141)
Refs django/channels#1181
1 parent 0a7d10e commit 6031d25

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

channels_redis/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ async def receive(self, channel):
383383
except asyncio.CancelledError:
384384
# Ensure all tasks are cancelled if we are cancelled.
385385
# Also see: https://bugs.python.org/issue23859
386+
del self.receive_buffer[channel]
386387
for task in tasks:
387388
if not task.cancel():
388389
assert task.done()
@@ -433,6 +434,9 @@ async def receive(self, channel):
433434
else:
434435
self.receive_buffer[message_channel].put_nowait(message)
435436
message = None
437+
except:
438+
del self.receive_buffer[channel]
439+
raise
436440
finally:
437441
self.receive_lock.release()
438442

0 commit comments

Comments
 (0)