From 8aebf2e19db106fdc5b6cd7495b7ba087daeb831 Mon Sep 17 00:00:00 2001 From: florimondmanca Date: Sat, 14 Dec 2019 15:08:45 +0100 Subject: [PATCH 1/2] Don't wait for stream_writer to close --- httpx/concurrency/asyncio.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/httpx/concurrency/asyncio.py b/httpx/concurrency/asyncio.py index bb795b1d62..6bba00d980 100644 --- a/httpx/concurrency/asyncio.py +++ b/httpx/concurrency/asyncio.py @@ -1,7 +1,6 @@ import asyncio import functools import ssl -import sys import typing from ..config import Timeout @@ -163,8 +162,6 @@ def is_connection_dropped(self) -> bool: async def close(self) -> None: self.stream_writer.close() - if sys.version_info >= (3, 7): - await self.stream_writer.wait_closed() class PoolSemaphore(BasePoolSemaphore): From 8a60a36b1a0820da32513cd9003879b739383a2d Mon Sep 17 00:00:00 2001 From: florimondmanca Date: Sat, 14 Dec 2019 15:27:49 +0100 Subject: [PATCH 2/2] Add comment on why wait_closed() is not called --- httpx/concurrency/asyncio.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/httpx/concurrency/asyncio.py b/httpx/concurrency/asyncio.py index 6bba00d980..633801f73a 100644 --- a/httpx/concurrency/asyncio.py +++ b/httpx/concurrency/asyncio.py @@ -161,6 +161,13 @@ def is_connection_dropped(self) -> bool: return self.stream_reader.at_eof() async def close(self) -> None: + # NOTE: StreamWriter instances expose a '.wait_closed()' coroutine function, + # but using it has caused compatibility issues with certain sites in + # the past (see https://github.com/encode/httpx/issues/634), which is + # why we don't call it here. + # This is fine, though, because '.close()' schedules the actual closing of the + # stream, meaning that at best it will happen during the next event loop + # iteration, and at worst asyncio will take care of it on program exit. self.stream_writer.close()