Skip to content

Fix client cleanup after malformed HTTP responses - #3715

Open
ryanchou1994 wants to merge 1 commit into
tornadoweb:masterfrom
ryanchou1994:fix/malformed-response-close
Open

Fix client cleanup after malformed HTTP responses#3715
ryanchou1994 wants to merge 1 commit into
tornadoweb:masterfrom
ryanchou1994:fix/malformed-response-close

Conversation

@ryanchou1994

Copy link
Copy Markdown

When a response has a malformed start line or header, SimpleAsyncHTTPClient can wait for the request timeout even though the stream has already closed. For example, HTTP/1.1 301\r\n produces HTTPTimeoutError instead of reporting the failed connection promptly.

The parser can raise HTTPInputError before need_delegate_close is set. Set that flag in the client-side error handler so the existing finally block notifies the delegate and releases the request. HTTP parsing rules and the server-side 400 response remain unchanged; callers receive HTTPStreamClosedError for 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 Continue responses, 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:

  • tox lint, docs and the complete py3 suite pass: 1,250 tests, with 56 existing skips on macOS and 54 on Linux.
  • The focused HTTP client/connection/server tests pass (19 tests).
  • Two earlier macOS runs hit existing timing-sensitive tests; both isolated reruns and the final full run passed without changing their timeouts or expectations.

Tests used local sockets only. Windows and optional curl/pycares/Twisted transports were not run locally.

Copilot AI lite review requested due to automatic review settings September 9, 2026 17:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants