[Django] #36193: AssertionError: Invalid ASGI message after request body: http.request

6 views
Skip to first unread message

Django

unread,
Feb 16, 2025, 3:38:54 PM2/16/25
to django-...@googlegroups.com
#36193: AssertionError: Invalid ASGI message after request body: http.request
-------------------------------------+-------------------------------------
Reporter: codedoga | Type: Bug
Status: new | Component: HTTP
| handling
Version: 5.0 | Severity: Normal
Keywords: ASGI, | Triage Stage:
http.disconect, | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
I suspect that with the feature introduced from Django 5.0 for handling
http.disconnect events. Something might be problematic under certain
conditions with async views in Django. I only saw this happening with
Nginx Unit and Django>=5.0. [https://code.djangoproject.com/ticket/33738]

Here is also the ticket on Nginx Unit github
[https://github.com/nginx/unit/issues/1561] it contains traceback, Unit
log and behavior described in more detail.
I also created demo project to reproduce this behavior:
[https://github.com/codedoga/nginx_unit_asgi_django]

Another thing I noticed is that if I override ASGIHandler with the one
used by Django<=5.0 it works without issues.
--
Ticket URL: <https://code.djangoproject.com/ticket/36193>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 17, 2025, 4:04:47 AM2/17/25
to django-...@googlegroups.com
#36193: AssertionError: Invalid ASGI message after request body: http.request
-------------------------------------+-------------------------------------
Reporter: Dominik Gasparic | Owner: (none)
Type: Bug | Status: closed
Component: HTTP handling | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: ASGI, | Triage Stage:
http.disconect, | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => invalid
* status: new => closed

Comment:

Hi Dominik, thank you for the ticket

In the issue you raised to Nginx Unit, you mentioned
> The same code works perfectly well with uvicorn and granian so I would
expect it to also work with Unit

This doesn't look like Django is at fault to me.

Please use our [https://docs.djangoproject.com/en/dev/faq/help/#how-
do-i-do-x-why-doesn-t-y-work-where-can-i-go-to-get-help support channels]
for help in identifying the source of the issue. There are volunteers who
can help to figure out what is going on here.
If after further investigation, it is confirmed that Django is at fault,
please re-open with more details.
--
Ticket URL: <https://code.djangoproject.com/ticket/36193#comment:1>

Django

unread,
Feb 18, 2025, 10:49:38 AM2/18/25
to django-...@googlegroups.com
#36193: AssertionError: Invalid ASGI message after request body: http.request
-------------------------------------+-------------------------------------
Reporter: Dominik Gasparic | Owner: (none)
Type: Bug | Status: closed
Component: HTTP handling | Version: 5.0
Severity: Normal | Resolution: invalid
Keywords: ASGI, | Triage Stage:
http.disconect, | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Carlton Gibson):

This looks like Unit isn't correctly handling the `more_body` key of the
`http.request` event.

https://asgi.readthedocs.io/en/latest/specs/www.html#request-receive-event

After an `http.request` event where `more_body` is `False` the only
permitted event is `http.disconnect`. Hence the assertion.
--
Ticket URL: <https://code.djangoproject.com/ticket/36193#comment:2>
Reply all
Reply to author
Forward
0 new messages