django / django/daphne

Django Channels memory leaks on opening new connections

Open
#373 28 comments 11 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.7k
Forks
292
Avg merge
2d 15h
Merged PRs (30d)
3

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](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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.