]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Fix bug when using client without timeouts in Python 3.6 (#383)
authorFlorimond Manca <florimond.manca@gmail.com>
Wed, 25 Sep 2019 11:31:50 +0000 (13:31 +0200)
committerSeth Michael Larson <sethmichaellarson@gmail.com>
Wed, 25 Sep 2019 11:31:50 +0000 (06:31 -0500)
httpx/concurrency/asyncio.py
tests/test_timeouts.py

index 696e32c148c263fcc83e3f0c9e202c5f54cc6c8a..5d3501447dad3600baf73db1410739593ee02dee 100644 (file)
@@ -81,6 +81,12 @@ class TCPStream(BaseTCPStream):
             except asyncio.TimeoutError:
                 if should_raise:
                     raise ReadTimeout() from None
+                # FIX(py3.6): yield control back to the event loop to give it a chance
+                # to cancel `.read(n)` before we retry.
+                # This prevents concurrent `.read()` calls, which asyncio
+                # doesn't seem to allow on 3.6.
+                # See: https://github.com/encode/httpx/issues/382
+                await asyncio.sleep(0)
 
         return data
 
index 8dc1e0800f8a2dfcd84982496ce2e281e34496b3..ff5273b9a9cd48a367cfca5217ded3f310c63f4d 100644 (file)
@@ -2,6 +2,7 @@ import pytest
 
 from httpx import (
     AsyncClient,
+    Client,
     ConnectTimeout,
     PoolLimits,
     PoolTimeout,
@@ -47,3 +48,13 @@ async def test_pool_timeout(server, backend):
             await client.get("http://localhost:8000/")
 
         await response.read()
+
+
+def test_sync_infinite_timeout(server):
+    """Regression test for a bug that occurred under Python 3.6.
+
+    See: https://github.com/encode/httpx/issues/382
+    """
+    no_timeout = TimeoutConfig()
+    with Client(timeout=no_timeout) as client:
+        client.get(server.url.copy_with(path="/slow_response/50"))