Repository navigation
Fix client cleanup after malformed HTTP responses - #3715
ryanchou1994 wants to merge 1 commit into
Conversation
|
Hi @bdarnell, friendly ping: the workflows on this PR are still waiting for approval to run. Happy to adjust anything if needed. Thanks! |
|
Closing this one: #3765 (merged 2026-10-06) includes the same fix in For what it's worth, the regression tests from this branch ( |
|
Thanks for the follow-up! And thanks for connecting this fix back to #2984. I think we probably don't need additional heavyweight tests for this two-line fix, but if there are specific cases that you think would benefit from dedicated coverage I'd consider a test-only PR to add them. |
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.