Skip to content

fix: serve the uWSGI protocol on the ASGI worker - #3724

Merged
benoitc merged 1 commit into
masterfrom
fix/asgi-uwsgi-protocol
Sep 1, 2026
Merged

fix: serve the uWSGI protocol on the ASGI worker#3724
benoitc merged 1 commit into
masterfrom
fix/asgi-uwsgi-protocol

Conversation

@benoitc

@benoitc benoitc commented Aug 31, 2026

Copy link
Copy Markdown
Owner

The ASGI worker with --protocol uwsgi behind nginx uwsgi_pass returned 502 on every request, logging uWSGI parse error: Invalid uWSGI header: incomplete header.

connection_made set up the HTTP/1 callback parser and left self.reader unset for every non-HTTP/2 connection, with no branch for protocol == "uwsgi". So data_received fed the HTTP/1 parser, the raw uWSGI bytes never reached the uWSGI handler, and _handle_connection_uwsgi read from AsyncUnreader(None) (an AttributeError that _read_chunk swallowed and surfaced as an incomplete header). Two further gaps surfaced once bytes flowed: the uWSGI request had no raw_path, and no ASGI body receiver was built for it.

Fix:

  • start a StreamReader for the uWSGI protocol so data_received feeds it, and dispatch to the uWSGI handler
  • build and feed the ASGI body receiver from the uWSGI body
  • set raw_path on the uWSGI request (from REQUEST_URI, else PATH_INFO)
  • stop AsyncUnreader._read_chunk swallowing non-EOF read errors so a misconfigured reader fails loudly

Adds tests/test_asgi_uwsgi_protocol.py (spawns a live ASGI+uWSGI gunicorn and speaks the binary protocol). The existing tests/docker/test_asgi_uwsgi/ behind-nginx smoke, previously broken, now passes all cases.

--worker-class asgi --protocol uwsgi behind nginx uwsgi_pass returned 502 on
every request with "Invalid uWSGI header: incomplete header": connection_made
set up the HTTP/1 callback parser and left the reader unset, so data_received
never fed the uWSGI handler and it read from a None reader.

Start a StreamReader for the uWSGI protocol so data_received feeds it, build
the ASGI request body for the app, and set raw_path on the uWSGI request.
Stop AsyncUnreader swallowing non-EOF read errors so a misconfigured reader
fails loudly instead of looking like an empty header.
@benoitc
benoitc merged commit 766d6cd into master Sep 1, 2026
28 checks passed
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

Successfully merging this pull request may close these issues.

1 participant