Fix client cleanup after malformed HTTP responses - #3715
Open
ryanchou1994 wants to merge 1 commit into
Open
Conversation
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.
When a response has a malformed start line or header,
SimpleAsyncHTTPClientcan wait for the request timeout even though the stream has already closed. For example,HTTP/1.1 301\r\nproducesHTTPTimeoutErrorinstead of reporting the failed connection promptly.The parser can raise
HTTPInputErrorbeforeneed_delegate_closeis set. Set that flag in the client-side error handler so the existingfinallyblock notifies the delegate and releases the request. HTTP parsing rules and the server-side 400 response remain unchanged; callers receiveHTTPStreamClosedErrorfor this failure instead of a later timeout.Related to #2984, specifically the malformed-response timeout discussed there.
Five real-socket regression tests cover malformed start lines and headers, including after one or two
100 Continueresponses, alongside valid-response controls. They also check callback counts, timer cleanup, and reuse of the single client slot. The four malformed cases fail against the original implementation and pass with this change.Validation on macOS and Linux:
toxlint, docs and the completepy3suite pass: 1,250 tests, with 56 existing skips on macOS and 54 on Linux.Tests used local sockets only. Windows and optional curl/pycares/Twisted transports were not run locally.