question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using asgiref.local.Local with gevent leads to memory leaks

See original GitHub issue

We use Django with Gunicorn and gevent workers. Since updating to Django 3, we started seeing some reasonably severe memory leaks in our web processes.

I bisected one of the leaks I could reproduce locally to https://github.com/django/django/commit/a415ce70bef6d91036b00dd2c8544aed7aeeaaed.

In particular, it seems to be caused by the switch from threading.local to asgiref.local.Local.

I investigated a fair bit. There seem to be a few things going on:

(Also, I’m not sure how gevent-friendly CLEANUP_INTERVAL = 60 is.)

It could be argued that gevent-related bugs are a problem with gevent. However, I think this problem is quite severe and also not easily noticed as it’s mostly a silent problem.

While any fixes (here or in gevent) would be appreciated, it would be good to document the incompatibility too.

(I tested gevent 1.4.0 and 1.5a3.)

Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
andrewgodwincommented, Feb 26, 2020

That’ll be the problem then. Hard to reason about threads when they’re… not threads.

I’ll need to think about the best approach to this one. I really don’t want to have asgiref depend on gevent at all, but detecting that threads aren’t threads is going to be tricky otherwise.

0reactions
andrewgodwincommented, Mar 19, 2020

Alright, I’ll get it merged in then, as it seems to solve at least two problems and not cause any issues!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak with gunicorn gevent stream responses and ...
I was able to correct this memory leak by removing gevent_zeromq and just using pyzmq==13.1.0 which includes gevent support.
Read more >
Understanding Memory Leaks in Java - Baeldung
A Memory Leak is a situation where there are objects present in the heap that are no longer used, but the garbage collector...
Read more >
memory used by gunicorn-gevent always increases, ideas?
When the app starts running everything looks fine but as I use it the memory usage starts going up as I send requests....
Read more >
memory leak in django app? - Google Groups
Is that enough RAM memory for a uWSGI/Gevent based WSGI app running Django? I'm running uWSGI with the --gevent switch in order to...
Read more >
Java Memory Leaks - Java Enterprise Performance | Dynatrace
A thread-local variable is basically a member field in the Thread class. ... Memory leaks due to overly complex and circular object structures...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found