Skip lingering close when response declines keep-alive - #13245
Draft
Ranjeeth11 wants to merge 2 commits into
Draft
Skip lingering close when response declines keep-alive#13245Ranjeeth11 wants to merge 2 commits into
Ranjeeth11 wants to merge 2 commits into
Conversation
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Merging this PR will not alter performance
Comparing Footnotes
|
The existing regression test for issue aio-libs#1800 only observed that the request body was never drained (via a StreamReader.readany spy), which is a side effect of the lingering loop rather than a direct check that the loop's guard was never entered. Add a wraps= spy on aiohttp.web_protocol.ceil_timeout - the per-iteration timeout the lingering loop uses and the only call to it reachable from this test - so the test now fails if the branch runs at all, not only if it happens to drain the payload.
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.
What changed
RequestHandler's lingering-close gate in the request-handling loop now also checksself._keepalivebefore starting the wait to drain an unread request body. Previously it only checkedself._force_close.Why
self._keepaliveis already set from the response'skeep_alivevalue earlier in the same loop iteration, but wasn't consulted here — unlike two other nearby checks in the same file (_process_keepalive, and the keep-alive-timer-arming condition) that already treat "keep-alive declined" and "force closed" as equivalent grounds to skip further keep-alive-related work. A handler callingresp.force_close()still triggered the full lingering wait despite declining keep-alive.User-visible behavior
Any response for which keep-alive is declined (
resp.force_close(),Connection: close, or HTTP/1.0 without keep-alive) now skips the lingering-drain wait instead of waiting up tolingering_timeseconds. Responses that keep the connection alive are unaffected.Tests
Added
test_force_close_response_skips_lingering_closeintests/test_web_functional.py, which spies onStreamReader.readany(identity-filtered to the request's own payload) to confirm the unread body is never drained whenresp.force_close()is called. Verified it fails on unfixed code and passes with the fix.Fixes #1800