]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
asyncio: Don't wait for the stream to close (#640)
authorFlorimond Manca <florimond.manca@gmail.com>
Mon, 16 Dec 2019 12:11:58 +0000 (13:11 +0100)
committerTom Christie <tom@tomchristie.com>
Mon, 16 Dec 2019 12:11:58 +0000 (12:11 +0000)
* Don't wait for stream_writer to close

* Add comment on why wait_closed() is not called

httpx/concurrency/asyncio.py

index bb795b1d626f0e39594ed40fb86f8c57fcdeb226..633801f73ac777867fb0c09963cdac6f7259c086 100644 (file)
@@ -1,7 +1,6 @@
 import asyncio
 import functools
 import ssl
-import sys
 import typing
 
 from ..config import Timeout
@@ -162,9 +161,14 @@ class SocketStream(BaseSocketStream):
         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()
-        if sys.version_info >= (3, 7):
-            await self.stream_writer.wait_closed()
 
 
 class PoolSemaphore(BasePoolSemaphore):