From: Florimond Manca Date: Wed, 25 Sep 2019 11:31:50 +0000 (+0200) Subject: Fix bug when using client without timeouts in Python 3.6 (#383) X-Git-Tag: 0.7.4~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cadb9a4d4c405de19324da3b8f192e887e0f36ac;p=thirdparty%2Fhttpx.git Fix bug when using client without timeouts in Python 3.6 (#383) --- diff --git a/httpx/concurrency/asyncio.py b/httpx/concurrency/asyncio.py index 696e32c1..5d350144 100644 --- a/httpx/concurrency/asyncio.py +++ b/httpx/concurrency/asyncio.py @@ -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 diff --git a/tests/test_timeouts.py b/tests/test_timeouts.py index 8dc1e080..ff5273b9 100644 --- a/tests/test_timeouts.py +++ b/tests/test_timeouts.py @@ -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"))