Stop parsing completed HTTP proxy responses. - #1762
Sakshamm-Goyal wants to merge 1 commit into
Conversation
|
What problem is this actually causing in real life? |
What is "the asyncio callback" in this context? |
|
The concrete effect I reproduced is an extra, uncaught event-loop exception during cleanup after a proxy rejects CONNECT with 407 (for example, incorrect proxy credentials). By “the asyncio callback” I meant The CONNECT response parser already completed when it reported 407. Cleanup resumes that exhausted generator, whose next I re-ran the loopback integration on Python 3.13.11: a real local CONNECT proxy, a WebSocket echo server, and the public |
Stop parsing completed HTTP proxy responses
When an HTTP proxy rejects CONNECT with 407 and closes the connection,
connect()raisesInvalidProxyStatusas expected, but the asyncio callback also raisesAttributeErrorby resuming the completed response parser. EOF followed by connection loss can also feed EOF twice.Treat the completed response future as terminal and share EOF handling. Seven tests cover success, rejection, malformed responses, cancellation, incomplete responses and trailing data. A local authenticated CONNECT tunnel reproduces the callback error before the fix and verifies echo/rejection without callback errors afterward.
Python 3.13 tests, full and per-module 100% coverage, Ruff and strict mypy pass. An initial synchronous reconnect timing failure passed on rerun with the repository CI timeout factor. Other Python/platform combinations weren't run locally.
Prepared and validated with an AI coding assistant. This is separate from the credential-decoding behavior in #1761.