Description
Hello! First of all, this is a great project and I wanted to thank all the maintainers for keeping it amazing!
For last two months, django-channels websockets on our production service have been periodically failing with OOM. Having researched it, it looks like a django-channels memory leak.
I think it may be related to opening new channel connections and then improperly closing them in channels_layer object. Opening multiple browser tabs leading to a single channels group increases memory usage, and closing them does not release the memory (the disconnect occurs though).
I have also managed to reproduce it on a simple project with minimal dependencies and steps to reproduce, so please feel free to check it out: https://github.com/yuriymironov96/django-channels-leak. This is a project based on django-channels tutorial.
Here are dependencies of the sample project:
- python = "^3.8"
- channels = "^3.0.3"
- channels-redis = "^3.2.0"
- channels-rabbitmq = "^3.0.0"
- Pympler = "^0.9"
- daphne = "^3.0.2"
I have tries both channels_redis
and channels_rabbitmq
, multiple servers (django debug server, daphne
, uvicorn
) and the issue still persists.
The sample benchmarks are:
- Server is launched, no browser tabs open: 49.3 MB;
- First browser tab opened: 51.2 MB;
- 20 browser tabs opened: 52.2 MB;
- All browser tabs closed: 52.2 MB;
- 20 browser tabs opened: 52.6 MB;
- All browser tabs closed: 52.6 MB;
It may look like a minor leak at this rate, but it is scales quickly and occurs frequently due to high load of our application.
Could you please have a look at it and share any ideas you have?