From ddf1cec65a0dc6c18d7a163ff2fc73b2eb134cce Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 25 Apr 2019 17:16:37 +0100 Subject: [PATCH] Drop connections from pool on connection exceptions --- httpcore/connection_pool.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/httpcore/connection_pool.py b/httpcore/connection_pool.py index 4ba83ec3..6eaef9be 100644 --- a/httpcore/connection_pool.py +++ b/httpcore/connection_pool.py @@ -110,7 +110,12 @@ class ConnectionPool(Client): timeout: typing.Optional[TimeoutConfig] = None, ) -> Response: connection = await self.acquire_connection(request.url.origin, timeout=timeout) - response = await connection.send(request, ssl=ssl, timeout=timeout) + try: + response = await connection.send(request, ssl=ssl, timeout=timeout) + except BaseException as exc: + self.active_connections.remove(connection) + self.max_connections.release() + raise exc return response async def acquire_connection( -- 2.47.3