Timeout during AnyIOStream.start_tls causes stuck connections in the pool when using AsyncHTTPProxy #905
Replies: 1 comment
|
The failure window described here is still visible in current main.
stream = await stream.start_tls(...)Only after TLS succeeds does it replace If So the cleanup invariant should be: once CONNECT succeeds, failure of TLS upgrade must make that tunnel connection unusable and close its underlying stream/connection before propagating the timeout/error. The critical cleanup should also be cancellation-safe, for the same reason response cleanup is shielded elsewhere in current async httpcore. A focused regression test can avoid a real proxy: have a mock proxy return a successful CONNECT and a network stream whose That targets the actual ownership transition—CONNECT has consumed the proxy connection, TLS failed before the remote HTTP connection was installed—rather than special-casing timeout as such. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Example
Hi!
Please excuse my hacky way to demonstrate the issue:
Setup:
To replicate:
proxy.py:proxy --hostname 127.0.0.1 --port 8080You should see that every time a timeout happens during
start_tls, after just having reconnected to the proxy, there is a new stuck connection in the pool that looks like this:<AsyncTunnelHTTPConnection ['http://127.0.0.1:8080', HTTP/1.1, ACTIVE, Request Count: 1]>Context
We have a bunch of Telegram bots on
python-telegram-botrunning behind a proxy. Once every couple of weeks they all simultaneously stop responding - judging by the logs this seems to be the root issue.All reactions