﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37385	"ASGI client disconnects log ""CancelledError exception in shielded future"" on Python 3.14+"	Natalia Bidart		"Since [https://github.com/django/django/commit/a013c821ea a013c821ea] (#37177), built-in middleware are sync-only, so under ASGI the default middleware chain runs in a thread and calls the view back through `async_to_sync()`. On Python 3.14+, a client disconnecting while the view is still running makes the `asyncio` logger emit an ERROR with a traceback:

{{{
CancelledError exception in shielded future
...
  File "".../asgiref/sync.py"", line 526, in __call__
    ret = await asyncio.shield(exec_coro)
asyncio.exceptions.CancelledError
}}}

The request itself is handled correctly. Python 3.14 changed `asyncio.shield()` to log the shielded future's exception if the outer task was cancelled, and asgiref's `SyncToAsync` shields the executor future, which ends with `CancelledError` when the handler cancels the request.

To reproduce, in a `startproject` project with the default `MIDDLEWARE`, add:

{{{#!python
async def slow_async(request):
    await asyncio.sleep(3)
    return HttpResponse(""ok"")


def slow_sync(request):
    time.sleep(3)
    return HttpResponse(""ok"")


urlpatterns += [
    path(""slow-async/"", slow_async),
    path(""slow-sync/"", slow_sync),
]
}}}

Serve it with an async server (`uvicorn mysite.asgi:application`) and run `curl --max-time 1 http://127.0.0.1:8000/slow-async/` (or `/slow-sync/`). The traceback is logged once the view finishes. The `asgi` tests also show it (`./runtests.py asgi --parallel=1`), though they pass."	Cleanup/optimization	new	HTTP handling	dev	Release blocker		async	Carlton Gibson	Unreviewed	0	0	0	0	0	0
