fix: serve the uWSGI protocol on the ASGI worker - #3724
Merged
Conversation
--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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The ASGI worker with
--protocol uwsgibehind nginxuwsgi_passreturned 502 on every request, logginguWSGI parse error: Invalid uWSGI header: incomplete header.connection_madeset up the HTTP/1 callback parser and leftself.readerunset for every non-HTTP/2 connection, with no branch forprotocol == "uwsgi". Sodata_receivedfed the HTTP/1 parser, the raw uWSGI bytes never reached the uWSGI handler, and_handle_connection_uwsgiread fromAsyncUnreader(None)(anAttributeErrorthat_read_chunkswallowed and surfaced as an incomplete header). Two further gaps surfaced once bytes flowed: the uWSGI request had noraw_path, and no ASGI body receiver was built for it.Fix:
StreamReaderfor the uWSGI protocol sodata_receivedfeeds it, and dispatch to the uWSGI handlerraw_pathon the uWSGI request (fromREQUEST_URI, elsePATH_INFO)AsyncUnreader._read_chunkswallowing non-EOF read errors so a misconfigured reader fails loudlyAdds
tests/test_asgi_uwsgi_protocol.py(spawns a live ASGI+uWSGI gunicorn and speaks the binary protocol). The existingtests/docker/test_asgi_uwsgi/behind-nginx smoke, previously broken, now passes all cases.