Skip to content

Deadlock when using concurrency in async views #1828

Closed
@salomvary

Description

@salomvary

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions