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

Deadlock when using concurrency in async views #1828

Closed
salomvary opened this issue Aug 30, 2023 · 5 comments
Closed

Deadlock when using concurrency in async views #1828

salomvary opened this issue Aug 30, 2023 · 5 comments

Comments

@salomvary
Copy link
Contributor

Hi folks,

First of all thanks for maintaining this amazing project! I've recently started migrating an existing project to asynchronous views and noticed that the view gets deadlocked when tasks are executed concurrently and the Debug Toolbar is installed.

If no tasks run concurrently (ie. using a sequence of awaits) or the Debug Toolbar is removed, everything seems fine.

Below is an example that hangs forever on await asyncio.gather:

async def get(request):
    (one_thing, another_thing) = await asyncio.gather(
        Thing.objects.filter(pk=1).afirst(),
        Thing.objects.filter(pk=2).afirst()
    )

    return HttpResponse(content=f"Hello {one_thing.pk} {another_thing.pk}")

I'm relatively new to Python asyncio and have therefore no idea what's going on. I see the ongoing async issues in this issue tracker but I am not sure what's the state of Django async support (or lack of it) is here. (Something that might be worth documenting on the Readme.)

These are the dependencies in use:

$ poetry show -T   
daphne               4.0.0   Django ASGI (HTTP/WebSocket) server
django               4.2.4   A high-level Python web framework that encourages rapid development and clean, pragmatic design.
django-debug-toolbar 4.2.0   A configurable set of panels that display various debug information about the current request/response.
psycopg2-binary      2.9.7   psycopg2 - Python-PostgreSQL Database Adapter

I can share a minimal test project if someone wants to have a look.

@tim-schilling
Copy link
Contributor

The toolbar is sync only at this time. If you'd like to open a PR to call that out explicitly in the Readme and installation docs, that would be helpful. There was another idea to log a message or not fail too. If you can help, it'd be appreciated.

salomvary added a commit to salomvary/django-debug-toolbar that referenced this issue Aug 30, 2023
salomvary added a commit to salomvary/django-debug-toolbar that referenced this issue Aug 30, 2023
salomvary added a commit to salomvary/django-debug-toolbar that referenced this issue Aug 30, 2023
@salomvary
Copy link
Contributor Author

The toolbar is sync only at this time. If you'd like to open a PR to call that out explicitly in the Readme and installation docs, that would be helpful. There was another idea to log a message or not fail too. If you can help, it'd be appreciated.

@tim-schilling Something like this? #1829

How big of an undertaking would be to add async support? (Full or partial). Looking at these issues, I have no idea: https://github.com/jazzband/django-debug-toolbar/issues?q=is%3Aissue+project%3Ajazzband%2F9+is%3Aopen

I'd be motivated to help, even with small contributions but am not familiar with the Toobar's internals (moderately familiar with Django internals, noob at Python async). Let me know if there are low hanging fruits to tackle.

tim-schilling pushed a commit that referenced this issue Aug 30, 2023
* Add note on lack of async support to Installation docs
* Add note on lack of async support to the Readme

#1828 (comment)
@tim-schilling
Copy link
Contributor

@salomvary Thank you for that PR and the offer to help.

The project for async compatibility is here: https://github.com/orgs/jazzband/projects/9

The main thing that you can help with that doesn't require much effort on my part is implementing tests that the toolbar would need to pass to be considered "working". This is issue #1819

@salomvary
Copy link
Contributor Author

I guess it does not make sense to keep this issue open then.

@salomvary
Copy link
Contributor Author

As I recently discovered, async or not, concurrent ORM queries are not yet a thing in Django, therefore this issue is even less of an issue in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants