Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak with rust task impl #500

Open
pmdevita opened this issue Jan 29, 2025 · 3 comments
Open

Memory leak with rust task impl #500

pmdevita opened this issue Jan 29, 2025 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@pmdevita
Copy link

pmdevita commented Jan 29, 2025

Using Granian 1.7.5, tested it with both Django and Quart under asginl and asgi modes respectively. The Python process under Granian seems to increase in RAM usage over time, most noticeably if the Python application is returning large responses like files.

Here's a small example using Quart

from quart import Quart

app = Quart(__name__)

@app.route("/")
async def hello():
    return "A" * 4 * 1000 * 1024

and a small example with Django (generate a new project and then throw this into the root urls.py)

from django.urls import path
from django.http import HttpResponse

def image(request):
    return HttpResponse("A" * 4 * 1000 * 1024, content_type="image/png")


urlpatterns = [
    path("", image, name="image")
]

Here's a graph showing the problem, this before when I was running with 1.7.5 and then after I downgraded back to 1.6.4. The large downspikes in memory usage on the left side is Kubernetes restarting the workers.

Image

Git bisected the issue to this commit here 0741845

Thank you for this project!

@gi0baro
Copy link
Member

gi0baro commented Jan 29, 2025

@pmdevita do you experience the same result forcing --task-impl asyncio?

@pmdevita
Copy link
Author

I do not, that does keep memory usage in check. Do you think this is maybe a uvloop problem then?

@gi0baro gi0baro added this to the 1.7 milestone Jan 29, 2025
@gi0baro
Copy link
Member

gi0baro commented Jan 29, 2025

No, it's probably just some bad code in ffi calls.
Gonna push a patch release later with --task-impl set to asyncio by default; at least until I figure out what's wrong.

@gi0baro gi0baro changed the title Memory leak, responses seem to remain in memory Memory leak with rust task impl Jan 29, 2025
@gi0baro gi0baro added the bug Something isn't working label Jan 29, 2025
gi0baro added a commit that referenced this issue Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants