Repository navigation
Conversation
76a9abb to
6db6963
Compare
6db6963 to
5e45f65
Compare
|
Thanks for this. One gap worth covering: Repro against this branch: import asyncio, httpcore
class Stall(httpcore.AsyncMockStream):
async def start_tls(self, ssl_context, server_hostname=None, timeout=None):
await asyncio.sleep(3600)
class Backend(httpcore.AsyncMockBackend):
async def connect_tcp(self, host, port, timeout=None, local_address=None, socket_options=None):
return Stall(list(self._buffer))
async def main():
async with httpcore.AsyncConnectionPool(
proxy=httpcore.Proxy("http://localhost:8080/"),
max_connections=1,
network_backend=Backend([b"HTTP/1.1 200 OK\r\n\r\n"]),
) as pool:
task = asyncio.create_task(pool.request("GET", "https://example.com/"))
await asyncio.sleep(0.05)
task.cancel()
try:
await task
except asyncio.CancelledError:
pass
print(pool.connections)
asyncio.run(main())
The third row uses the pattern except BaseException as exc:
with AsyncShieldCancellation():
await self._connection.aclose()
raise excFor context on the impact: we hit the timeout path in production with httpcore 1.0.9 behind a CONNECT proxy, on a client with |
|
I independently reproduced the proxy-tunnel leak on httpcore 1.0.9 with httpx 0.25.2. The cancellation gap described above also reproduces with a real loopback HTTP CONNECT proxy, using uvloop and a one-slot connection pool. The proxy accepts CONNECT with a 200, then waits after receiving the TLS ClientHello. This lets the test trigger a handshake timeout, an explicit I tested the proposed async change that catches |
Summary
Close proxy tunnel connection when TLS raises during CONNECT (#921)
This happened when I use python-telegram-bot library.
Details
Checklist