diff --git a/httpcore/_async/connection_pool.py b/httpcore/_async/connection_pool.py index 10b7a55a..a667cbdb 100644 --- a/httpcore/_async/connection_pool.py +++ b/httpcore/_async/connection_pool.py @@ -31,7 +31,8 @@ def unset_connection(self) -> None: async def wait_for_connection( self, timeout: Optional[float] = None ) -> AsyncConnectionInterface: - await self._connection_acquired.wait(timeout=timeout) + if self.connection is None: + await self._connection_acquired.wait(timeout=timeout) assert self.connection is not None return self.connection diff --git a/httpcore/_sync/connection_pool.py b/httpcore/_sync/connection_pool.py index 1a7025e1..379a5fce 100644 --- a/httpcore/_sync/connection_pool.py +++ b/httpcore/_sync/connection_pool.py @@ -31,7 +31,8 @@ def unset_connection(self) -> None: def wait_for_connection( self, timeout: Optional[float] = None ) -> ConnectionInterface: - self._connection_acquired.wait(timeout=timeout) + if self.connection is None: + self._connection_acquired.wait(timeout=timeout) assert self.connection is not None return self.connection