fix: announce Connection: close from the ASGI worker - #3726
Open
dylanpulver wants to merge 1 commit into
Open
Conversation
The ASGI worker decides not to reuse a connection (client sent Connection: close, --keep-alive 0, worker shutting down, or a uWSGI response delimited by EOF) and then closes it without ever sending a Connection header. RFC 9112 section 9.6 requires a server that will not reuse a connection to say so, and the sync WSGI worker already does it in Response.default_headers(). Extract the keepalive decision into _will_close() so the header emitted by _send_response_start() and the reuse decision returned by _handle_http_request() come from one predicate and cannot drift. An app-supplied Connection header is left alone.
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 decides not to reuse a connection and then closes it without sending a
Connectionheader. RFC 9112 §9.6 requires a server that will not reuse a connection to say so, and the sync WSGI worker already does, inResponse.default_headers().Measured against that sibling, one server each, raw socket:
Connection: close--keep-alive 0A client seeing an HTTP/1.1 response with no
Connectionheader treats it as persistent (§9.3) and reuses a socket the server already closed. Also reached by worker shutdown and by a uWSGI response delimited by EOF._send_response_start()and the keepalive return of_handle_http_request()now read one predicate,_will_close(), so the announced framing cannot drift from the framing used. An app-suppliedConnectionheader is left alone.Verification, same env each run:
protocol.py, keep tests) → 8/8 new tests fail, 0 pre-existingclose=request.should_close()) passes all 2044 — it covers only the client-requested case; live it still closes unannounced under--keep-alive 0. Hence the shared predicate rather than a second derivation.pylint 3.3.2 10.00/10 and pycodestyle clean.