asgiref icon indicating copy to clipboard operation
asgiref copied to clipboard

[3.8 regression] Deadlock with `async_to_sync` → `sync_to_async` → `async_to_sync` → `create_task` → `sync_to_async`

Open andersk opened this issue 10 months ago • 2 comments

This code, minimized from the Zulip server, worked in asgiref 3.7.2, but deadlocks in 3.8.0, 3.8.1, and current main (abc69a054aa440ef42c939b5a197df05c3ad48d2). A Git bisection implicates d920c3c44f59ef037be3a09a41a5640014cfb1e2 as the first broken commit:

  • #367, cc @jthorniley
import asyncio

from asgiref.sync import async_to_sync, sync_to_async


async def inner() -> asyncio.Task[None]:
    return asyncio.create_task(sync_to_async(print)("inner"))


async def main() -> None:
    task = await sync_to_async(async_to_sync(inner))()
    await task


async_to_sync(main)()

andersk avatar Feb 05 '25 01:02 andersk

Any updates on this bug? Thanks!

bartekgruszka avatar Mar 07 '25 07:03 bartekgruszka

@bartekgruszka Trying out the branch from #494 would be helpful. (See related discussions from three of you want to dig deeper.)

carltongibson avatar Mar 07 '25 07:03 carltongibson