diff --git a/httpcore/_async/connection_pool.py b/httpcore/_async/connection_pool.py index 96e973d0..19f438f1 100644 --- a/httpcore/_async/connection_pool.py +++ b/httpcore/_async/connection_pool.py @@ -403,7 +403,10 @@ async def __aiter__(self) -> typing.AsyncIterator[bytes]: async for part in self._stream: yield part except BaseException as exc: - await self.aclose() + try: + await self.aclose() + except BaseException: + pass raise exc from None async def aclose(self) -> None: diff --git a/httpcore/_sync/connection_pool.py b/httpcore/_sync/connection_pool.py index 9ccfa53e..b31924f6 100644 --- a/httpcore/_sync/connection_pool.py +++ b/httpcore/_sync/connection_pool.py @@ -403,7 +403,10 @@ def __iter__(self) -> typing.Iterator[bytes]: for part in self._stream: yield part except BaseException as exc: - self.close() + try: + self.close() + except BaseException: + pass raise exc from None def close(self) -> None: